Hello C++ world, I am need of your help. What I need is search terms because I am obviously looking in the wrong places because I can't get my answer. I have a program that takes in numeric input and I want to give the user an error if they input a string. So what am I looking for? I have searched online for C++ errors for hours and found maybe only 5 examples but, when I plug them into my program it is a no go. Can you please help me? Thanks in advance.
Thank you vichu8888 for your response. I got it working just fine now but, I have my program set up so after it's done running it asks the user if they would like to run it again using a while loop. When I pres 'y' for yes it gives me my error how do I prevent this. This is the part of the code I used:
1 2 3 4 5 6 7 8 9 10
while (true) {
cout << "Please enter a valid number: ";
getline(cin, input);
// This code converts from string to number safely.
stringstream myStream(input);
if (myStream >> myNumber)
break;
cout << "Invalid number, please try again" << endl;
}
char response;
do
{
while (true)
{
cout << "Please enter a valid number: ";
getline(cin, input);
// This code converts from string to number safely.
stringstream myStream(input);
if (myStream >> myNumber)
break;
cout << "Invalid number, please try again" << endl;
}
cout<<"Do you check for another(y/n): ";
cin>>response;
response=toupper(response);
cin.ignore();
}while(response=='Y');