for loop

Hi..plz guide me how write this code.....!
n also tell its starting code/iostream
The program should display like;

Please Enter Grade (‘A’ OR ‘B’ )

Then the program should take 10 inputs one by one,

• After taking 10 inputs, you should display no. of A grades.
• If A grades are less than or equal to 2, you should display a message “Your class is Poor!”.
• If A grades are less than or equal to 7, you should display a message “Your class is Good!”.
• If A grades are greater than or equal to 8, you should display a message “Your class is Brilliant!”.
• The user should enter either A or B. If user has entered other than A or B, e.g. C,D,E etc. Your program should display a message like;
"Please Enter 'A' or 'B' grade only!"
Sample Input and Output

Please Enter Grade of student 1 :
A
Please Enter Grade of student 2 :
A
Please Enter Grade of student 3 :
B
Please Enter Grade of student 4 :
A
Please Enter Grade of student 5 :
B
Please Enter Grade of student 6 :
B
Please Enter Grade of student 7 :
A
Please Enter Grade of student 8 :
B
Please Enter Grade of student 9 :
C

Please Enter ‘A’ or ‘B’ grade only!
Please Enter Grade of student 9 :
A

Please Enter Grade of student 10 :
Last edited on
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
#include <iostream>

using namespace std;

int main()
{
char grade[10];
int a = 0;

for (int x = 0;x < 10;x++)
{
do{
cout << "Please Enter Grade of student " << x + 1 << " : ";
cin >> grade[x];
if(grade[x] != 'A' && grade[x] != 'B') cout << "Please enter \'A\' or \'B\' grade only!";
else if(grade[x] == 'A') ++a;
}while (grade[x] != 'A' && grade[x] != 'B');
 
}
if(a <= 2) cout << "Your class is Poor!" << endl;
else if (a <= 7) cout << "Your class is Good!" << endl;
else cout << "Your class is Brilliant!" << endl;
cout << "Number of \'A\' grades in your class is " << a << endl;
cin.ignore();
cin.get();
return 0;
}


Hope this helps!
Last edited on
Thank you sooooooooooo much Airman..thnx :)
Topic archived. No new replies allowed.