View Single Post
  #1 (permalink)  
Old 04-24-2008, 11:18 AM
Lab Lab is offline
Newbie
 
Join Date: Apr 2008
Location: Clifton Park, NY
Age: 44
Posts: 3
Credits: 0
Rep Power: 0
Lab is on a distinguished road
Exclamation Input Validation

New to programming(just a few weeks into it) and 1st forum ever joined so bare with me while I go thru the learning curve on how forums work.

Assignment is as follows:

Write a program that will ask a user to enter the current Tempeature
(-50 to 50,decimal), windspeed(3 to 150, whole number) and ask whether
thier input was in Fahrenheit or Celcius(f or c). It should then
echo the temperature and wind speed entered in BOTH Fahrenheit and Celcius
(to 1 decimal place) and output the wind chill in BOTH Fahrenheit and Celcius.
(to 1 decimal place).

I wrote it using an example the instructor showed in class as follows:
(only part of code)

Question: How do I validate only a number is entered?

Code:
		do// loop to test valid windspeed entered.
			{      
			cout << "Enter Wind speed (3 to 150):";
			cin >> windspeed;

			if ((windspeed < 3) || (windspeed > 150))
				{
				cout << "Please re enter a windspeed"
					<< " between 3 and 150:";
				cin >> windspeed;
				}
			else
				wsFlag = true;
			}while (wsFlag != true);// end windspeed validation loop.
the problem is if a charachter is entered rather than a number the programm goes crazy to say the least

I thought I saw a previous post relating to this but cannot find it again!!
Thank you all

Last edited by WingedPanther; 04-24-2008 at 07:56 PM. Reason: add code tags
Reply With Quote

Sponsored Links