Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You are working in a university, and the head of the department assigned to you the task of writing a C++ program that allows students to enroll in courses. The program should also update courses information after each enrollment, and issue the course table to the student. The student can enroll in maximum two courses. The program ends if the student entered the letter f or after enrolling in two courses. Assume that three courses are opened and their information.

when i open the program and input the course name and id nothing happen i also couldn't update the courses.

What I have tried:

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
    string course_name,u_course_name,a,b,c,d;
    int u_courseID,courseID,maxnbr,nbenrolled,count,i;
    char y;
    count=0;
    i=0;
    ifstream infile;
    infile.open("courses.txt");
    if(!infile)
    {
        cout<<"error"<<endl;
        return 0;
    }
    infile>>courseID>>course_name>>maxnbr>>nbenrolled;
    infile>>courseID>>course_name>>maxnbr>>nbenrolled;
    for  (i=0;infile,i<3;i++)
    {
        cout<<"please enter your choice in the form ( courseID , coursename )"<<endl;
        cin>>y>>u_courseID>>y>>u_course_name>>y;
        infile>>courseID>>course_name>>maxnbr>>nbenrolled;
        while(count<2)
        {
            if((u_courseID=='f') || (y=='f') || (u_course_name =="f"))
            {
                cout<<"Program is terminating....";
                return 0;
            }
            else if((courseID==u_courseID) && (course_name==u_course_name) && (nbenrolled<maxnbr))
            {
                cout<<"you are enrolled in the following course"<<endl<<setw(18)<<"**********"<<endl<<
"courseID : "<<courseID<<setw(25)<<"course name : "<<course_name<<endl;
                nbenrolled++;
                count++;
            }
            else if((courseID==u_courseID) && (course_name==u_course_name) && (maxnbr==nbenrolled))
            {
                cout<<"this course is full"<<endl;
            }
            i++;
        }
    }
    return 0;
}
Posted
Updated 6-Apr-16 22:53pm
v2

1 solution

So use the debugger and find out what is going on!
You'l probably find that the cin line is where it stops:
C++
cin>>y>>u_courseID>>y>>u_course_name>>y;
Why?
Because it's asking for five inputs, and you are probably only giving the two you asked for...
 
Share this answer
 
Comments
Mhaalazri 7-Apr-16 5:07am    
i used them for the ( ( and , and ))
OriginalGriff 7-Apr-16 5:23am    
And?
I'd read it in as a single string, and parse out the bits I wanted: check it starts and ends with the brackets (though that may annoy users, so I'd probably just want two inputs, prompted separately), and that it contains the comma. If it does, split out the two strings and convert one to an integer.
Mhaalazri 7-Apr-16 5:37am    
sorry i meant the comma and parentheses

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900