Answer on Question #44822- Programming, C++
1. Read in characters from the user until user enters 'z', then print out how many a's were entered. The below program does not count the number of 'a' the user has inputted. Please see the code below. Do I need to use array or I can do it without array, if yes please let me know how without using array.
Solution.
#include <iostream>
using namespace std;
void main()
{
char letter[100];
int x=0;
cout << "Please enter letter(s): ";
cin >> letter;
for (int i = 0; i < strlen(letter); ++i)
{
if (letter[i] == 'a')
{
x++;
}
if (letter[i] == 'a')
{
break;
}
}
cout << "The number(s) of letter 'a' entered is/are: " << x << endl;
system ("pause");
}
}http://www.AssignmentExpert.com/</iostream>
Comments