can someone tell me how to make it impossible for a user to type a 'userchoice1[x]' value that does not range from 1 - 10. If you also know a way I can make the user input another value for the 'userchoice1[x]' variable if it is less than 1, I'll appreciate you share the knowledge with me. please see the short code below | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

can someone tell me how to make it impossible for a user to type a 'userchoice1[x]' value that does not range from 1 - 10. If you also know a way I can make the user input another value for the 'userchoice1[x]' variable if it is less than 1, I'll appreciate you share the knowledge with me. please see the short code below

for (int x=0; x<5; x++) { cin>>userchoice1[x]; if (userchoice1[x]<1) { cout<<"Number must not be less than 1." <<endl; } }

29th Dec 2016, 1:28 PM
Cody Arthur
Cody Arthur - avatar
2 Answers
+ 4
write again: cin>>userchoise1[x]
29th Dec 2016, 1:36 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
In the IF block decrement the x so that you still await input to the invalid variable.
29th Dec 2016, 3:04 PM
Norbivar
Norbivar - avatar