i need to display number of students doing each course, seemingly it displays the first number well but the second time i try it adds all the students doing all courses. here's the code below:
Expand|Select|Wrap|Line Numbers
- {
- string str;
- int n, count = 0;
- cout<<"Enter number of courses: ";
- cin>>n;
- for(int i=0; i<=n-1; i++)
- {
- cout<<"Enter course: ";
- cin>>str;
- for(int i=0; i<=str.size(); i++)
- {
- if(str == stud[i].cours)
- {
- count++;
- cout<<"Number of students doing "<<str<<" are "<<count<<endl;
- }
- }
- }
- }