I tried to make small program that asks the user how many Asterisks (*) it should print out. The user responds with a number then the program prints that number of asterisks. The number of asterisks to print should be stored in a variable. Finally the program asks the user if it should start over, and repeats as many times as the user wants. The prompt to run the program again should look like the one below, and should wait at the end of the line for the user input.
Do you want go again? (y/n):
I want to know the code that make by two different way. (while and for)\
You should post what you have so far...no one is going to give you the answers to your homework. Are you stuck on the whole thing? Or just the part where it asks the user to run again or not? Good luck!
#include <iostream>
usingnamespace std;
int main(){
char question;
cout << "Do you want to start the program?" << endl;
cout << ">";
cin >> question;
while (question != 'n') {
int n_asterisks;
cout << "How many asterisks do you want to print out?" << endl;
cout << ">";
cin >> n_asterisks;
for (int i = 0; i < n_asterisks; ++i) {
cout << "*" << endl;
}
}
return 0;
}
Only thing missing is that the program starts automatically after it prints out the asterisks. It doesn't ask you if you want to run the program. Though I have made the code so that you should be able to modify it for your needs.