# Need Urgent assistance the given post with solution

 Tweet
4 replies [Last post]
bilzi
Offline
Last seen: 9 years 22 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;

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;

Sample Input and Output

A
A
B
A
B
B
A
B
C

A

A

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

int main()
{
char name[20], name1[]="A",name2[]="B";
cout<<"Enter grade 'A' OR 'B' :";
for(i=0;i<9;++i)
cin>> name[i];
{

}

aamiraarfi
Offline
Last seen: 4 years 37 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 22 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
Offline
Last seen: 4 years 37 weeks ago
Joined: 2009-11-02
bOt Points: 457
welcome

u r most welcome n walaikum esalaam