-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab11_1.cpp
44 lines (43 loc) · 961 Bytes
/
lab11_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<string>
using namespace std;
int main(){
int count[5] = {}; //Declare array count for counting A,B,C,D,F and initialize all element = 0
cout << "Please input grade of each student (A-F) or input 0 to exit.\n";
int i=1;
string A, B, C, D, F,grade;
do{
cout << "Student [" <<i<<"]: ";
getline(cin,grade); //The loop must be terminated when grade = '0'
if(grade=="A")
{
++count[0];
}else if(grade=="B")
{
++count[1];
}else if(grade=="C")
{
++count[2];
}else if(grade=="D")
{
++count[3];
}else if(grade=="F")
{
++count[4];
}else if(grade=="0")
{
break;
}else{
cout<<"Wrong input. Please input again.\n";
i--;
}
i++;
}while(grade!="0");
cout << "In total "<<i-1<<" students.\n";
cout << "A = " << count[0] <<", ";
cout << "B = " << count[1] <<", ";
cout << "C = " << count[2] <<", ";
cout << "D = " << count[3] <<", ";
cout << "F = " << count[4] ;
return 0;
}