### C++ input validation

During winter when it is very cold, typically, everyone would like to know the windchill factor, especially, before going out. Meteorologists use the following formula to compute the windchill factor, W:
W = 35.74 + 0.6215 * T – 35.75 * V^0.16 + 0.4275 * T * V^0.16,
Where V is the wind speed in miles per hour and T is the temperature in degrees Fahrenheit. Write a program that prompts the user to input the wind speed, in miles per hour, and the temperature in degrees Fahrenheit. The program then outputs the windchill factor. Your program must contain at least two functions: one to get the user input and the other to determine the windchill factor.
That is my assigment one of the functions needs to be reference parameters to pass the values back to main (which I need help on) The other one is the input validation the windchill range is _45 to 45 F and the win speeds 3 to 60 mph but when I test it for values that are between that range it doesn't calculate it gives me my own message that i am out of range. What did I do wrong?
Here is my code:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293`` ``````#include #include #include using namespace std; static double gWindChill[11][12]; double calcWindChill (int degree, int mph); double lookupWindChill (int degree, int mph); double interpolateWindChill (int degree, int mph); int main (void) { int degree, mph; for (int i = 0; i < 11; i++) for (int j = 0; j < 12; j++) gWindChill[i][j] = calcWindChill (-45 + i * 5, 5 + j * 5); while (true) { static double result; cout << " Degree (F): "; cin >> degree; cout << " Wind speed (MPH): "; cin >> mph; if ((degree < -45 || degree > 45) || (mph < 3 || mph > 60 || mph % 3 != 0)) { cout << " At least one value is out of range!\n" << " Ranges are:\n" << " - Temperature (-45 - 45)\n" << " - Wind speed (3 - 60) in increments of 5\n" << endl; return 1; } result = lookupWindChill (degree, mph); cout<
Last edited on
And your expected example output (same input) that you should have?

Hope this helps :)
this is my output:
 ``` Degree (F): 32 Wind speed (MPH): 32 At least one value is out of range! Ranges are: - Temperature (-45 - 45) - Wind speed (3 - 60) in increments of 5 Press any key to continue . . .```

and these are the numbers i need to test my program with
 RUN YOUR PROGRAM with the following script:
 ```Wind Speed Temperature 32 32 25 50 46 40 61 60 15 15 0 ```
Last edited on
 32 32 25 50 46 40 61 60 15 15 0

You showed an array of numbers and certainly I haven't understood these numbers.
Those numbers are the ones I need to test my code with the left side is the wind speed and the right the temperature. They are not in my code just to test.
 Degree (F): 32 Wind speed (MPH): 32 At least one value is out of range! ...

This is right or wrong result? Correct output for this input?
Last edited on
Okay I fixed my code so it is easier to read now.
 cout << " At least one value is out of range!\n" << " Ranges are:\n" << " - Temperature (-45 - 45)\n" << " - Wind speed (3 - 60) in increments of 5\n" << endl;

Yes, the input validation for the windchill range is -45 to 45 F and the win speeds 3 to 60 mph.
 cout << " Degree (F): "; cin >> degree; cout << " Wind speed (MPH): "; cin >> mph; if ((degree < -45 || degree > 45) || (mph < 3 || mph > 60 || mph % 3 != 0))
 degree = 32; mph = 32; ............................................. degree < -45 (32 < -45) - Wrong !!! degree > 45 (32 > 45) - Wrong !!! mph < 3 (32 < 3) - Wrong !!! mph > 60 (32 > 60) - Wrong !!! mph % 3 != 0 (32 % 3 = 2) - Right !!! Then output is : [quote] cout << " At least one value is out of range!\n" << " Ranges are:\n" << " - Temperature (-45 - 45)\n" << " - Wind speed (3 - 60) in increments of 5\n" << endl;

 `mph % 3!=0`