Complete C++ nooby and have a question that's beyond what my prof has taught

Mar 3, 2017 at 8:43pm
Essentially I'm really green when it comes to C++ I've tried going through tutorials and text books to find the elements for the following question but seem to be grasping at straws.

I need to have a user input a character and restrict it to 1 character, or enter q to quit. While the character is not q, it adds + 1 to counter. Once a character enters q, the screen is cleared and a statement is displayed to the user as many times as the counter went up 1. So in this situation I need it to say hi x however many time a character other than q was entered.

My question on it is should I be using : if( n == 'q' || n == 'Q')
break;
for it to end the while loop? and I'm a bit lost on how to have it repeat hi, by the amount on the counter.
Mar 3, 2017 at 10:43pm
is this what you need?

int ctr = 0;
char n = 0;

//do we do it once anyway, or is the first char typed "free" to the user??
//that is, is char 1 counted, or not?

while (n!= 'q' && n!='Q')
{
cout << 'hi' << endl;
ctr++;
cin << n; //you can check out getch, getche here for fun.
}

system("cls"); //system is frowned upon, but we can talk alternatives later.
cout << etc...
Last edited on Mar 3, 2017 at 10:49pm
Topic archived. No new replies allowed.