-
Error Message
I need the user to input a number, but the number must be above 1 and below 50 and it must be a number, not a symbol or letter. The input will then show up as asterisks, such as if they input 5 they would then see *****. I need a function that outputs an error message if the input is invalid. How do I ensure that the input will be correct and let the user know when it isn't?
Any help would be appreciated
-
Sure, this can be easyly done:
#include <iostream.h>
int main()
{
int input;
unsigned short int i;
cout << "Enter a number 1-50\n";
cin >> input;
if(input > 50 || input < 1){
cout << "Invalid\n";
return 0;//exit
}
for(i=0; i<input; i++){
cout << "*";
}
return 0;
}
hope this helps you
Popular pages
Recent additions