|
-
March 6th, 2008, 10:58 PM
#1
Count Grades
My assignment was to create a program that inputs letter grades (A, B, C, D, F), counts how many of each they are, and outputs the results.
Here is what I have so far:
#include <iostream>
#include <string>
using namespace std;
int main()
{string grade;
int gradeA=0, gradeB=0, gradeC=0, gradeD=0, gradeF=0;
cout<<"Please enter a letter grade or '-1' to quit: ";
cin>>grade;
while(grade!=-1)
{if(grade==A)
gradeA++;
else if(grade==B)
gradeB++;
else if(grade==C)
gradeC++;
else if(grade==D)
gradeD++;
else
gradeF++;
cout<<"Please enter another letter grade or '-1' to quit: ";
cin>>grade;
}
cout<<endl<<"The total number of letter grades are:"<<endl;
cout<<gradeA<<" As."<<endl;
cout<<gradeB<<" Bs."<<endl;
cout<<gradeC<<" Cs."<<endl;
cout<<gradeD<<" Ds."<<endl;
cout<<gradeF<<" Fs."<<endl<<endl;
return 0;
}
I believe my problem is with this line:
while(grade!=-1)
Can anyone help me understand my mistakes? Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|