Tuesday, July 14, 2009

I defined a variable x int in C++....?

x is a user defined variable in a program as simple as converting fahrenheit; if you enter a letter, it comes out as 32 degrees F; 0 degrees C. Is there any way to tell C++, "If the user enters a letter for x, than say "You entered a letter instead of number. Please try again." ?

I defined a variable x int in C++....?
Answer at link below. You basically have to loop through all the characters in the input string and test each one to see if it is a digit; if any of the characters fail, exit the loop and display the error message.
Reply:You'd have to set it up as a loop, and if a number wasn't entered, you can have it display the error message and repeat.


No comments:

Post a Comment