Need Urgent assistance the given post with solution

4 replies [Last post]
bilzi
Offline
Last seen: 9 years 15 weeks ago
Joined: 2010-11-03
bOt Points: 62

You are required to write a program which should take input from user in the form of characters A or B. Based upon user’s input you should calculate no. of A grades. You should use while loop or do/while loop for taking input and if / else condition for making decisions.
Detailed Description:

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 :

A

bilzi
Offline
Last seen: 9 years 15 weeks ago
Joined: 2010-11-03
bOt Points: 62
kindly correct and complete it?

int main()
{
char name[20], name1[]="A",name2[]="B";
int Agrade,Bgrade,sum, i,j,k;
cout<<"Enter grade 'A' OR 'B' :";
for(i=0;i<9;++i)
cin>> name[i];
cout<< "Total number of Agrade";
for(sum=0;sum<=Agrade;++sum)
cin>>name1[Agrade];
while(sum<=Agrade)
{
cout<<"total number of Agrade"< }

}

aamiraarfi
aamiraarfi's picture
Offline
Last seen: 4 years 30 weeks ago
Joined: 2009-11-02
bOt Points: 457
Here is a correct code

Hi bilzi I'm glad you tried the code, here is a better code,

#include <iostream.h>

int main()
{
char name[20];
int Asum=0;
int Bsum=0;
int i;
cout<<"Enter grade 'A' OR 'B' :\n";
for(i=0;i<9;i++)
{

cin>> name[i];
if (name[i]=='A')
{Asum=Asum+1;}
if (name[i]=='B')
{Bsum=Bsum+1;}

}
cout<< "\nTotal number of A grade is "<<Asum;
cout<< "\nTotal number of B grade is "<<Bsum;

}

Compile it on the online compiler

Input as

A
B
A
B
A
A
A
B
B

You will get this output:

Enter grade 'A' OR 'B' :

Total number of A grade is 5
Total number of B grade is 4

Rest you can do it on your own.

Always try problems on your own first. And try to understand what was wrong with your code. for eg. the while loop in your code will go into infinite loop . Learn more aboout strings and integers and other data types. Hope it helps :D

 

bilzi
Offline
Last seen: 9 years 15 weeks ago
Joined: 2010-11-03
bOt Points: 62
Special thanks aamiraarfi

Thank you very much for giving me direction. i have done it now. I don,t know how can i thank you dear brother.

Salam O Alykum.

aamiraarfi
aamiraarfi's picture
Offline
Last seen: 4 years 30 weeks ago
Joined: 2009-11-02
bOt Points: 457
welcome

u r most welcome n walaikum esalaam

And please tell ur friends about online c compiler on botskool.com