//3. Read in characters from the user until user enters 'z', then print out how many a's were entered
Please see the below code. However the code is not counting the number of 'a' the user has inputted.
Would I have to use array? or is there a way to do it without array if yes please help me thanks.
#include <iostream>
using namespace std;
void main ()
{
char letter;
int x=0;
cout << "Please enter letter(s): ";
cin >> letter;
while (letter=='a')
{
x = letter+1;
if (letter!= 'z')
{
cin >> letter;
}
}
cout << "The number(s) of letter 'a' entered is/are: " << x << endl;
system ("pause");
Comments
Leave a comment