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