# 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
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