Answer:
#include <iostream>
using namespace std;
int main()
{
char numbers[4];
cout<<"Create a histogram chart."<<endl;
cout<<"Enter your number as 4 characters: ";
cin >> numbers;
for (int i=3; i>=0; i--) {
int ascii_value = numbers[i];
int number = numbers[i] - '0';
if (ascii_value >=48 && ascii_value <=57) {
cout << number;
for (int j=number-1; j>=0; j--) {
cout << "*";
}
}
else {
cout << "a ?";
}
cout << endl;
}
}
Explanation:
Declare a character array with length 4,
Ask user to enter values,
Create a nested for loop; first loop <u>holds the values and their ASCII values for each character</u>,
<u>Check the ASCII values</u> for each character, if they are <u>between 48 and 57</u>, that means they are numbers. In this case, print the number and go to the inner loop and print the stars accordingly,
If ASCII values are not in the range, print a ?,
Go to the new line after each character