Which loop should I use?

Okay saying that I have this line of code
1
2
cout<<"Number of characters: ";
cin >> n;


And I want the user to input nothing higher than 100 and nothing lower than 1.

Which loops should I use to make the output something like this while running the program

Number of characters: 121
Invalid input, please input a number 1-100

Number of characters: 60

(here it goes on to the next line of code w/e it may be)


Something like that.

I know that I don't use a for loop for sure
But that's basically all I remember atm.

I tried a while loop but it's an infinite loop
Aka I tried something like
1
2
3
4
5
cout<<"Number of characters: ";
cin >> n;
while(n>100 || n<1){
cout<<"invalid number, please input a number 1-100!"<<endl;
}


^ keeps telling me it's wrong number since I never changed n again so if it's true then it will always be true ..


Nevermind, I was dumb ;-; Fixed it.
Last edited on
Topic archived. No new replies allowed.