For the weather program, validate that the temperatures are between -20 and 120 degrees and validate that the user has typed an acceptable answer in response to being asked if it is windy.Do not let them continue until an appropriate answer is received. I need help with the "while windy Y || N validating statement" If the user types the appropriate answer the program continues if not they get a "invalid entry" statement Id appreciate any help
#include<iostream>
usingnamespace std;
int main()
{
// variables
double temp;
char windy; // Y or N
/* asking user the temp and
validating */
cout << " What is the temperature outside in Fahrenheit? ";
cin >> temp;
while ((temp <= -20) || (temp >= 120))
{
cout << " Invalid entry !!! Please enter a temperature\n between -20 and 120 degrees\n";
cin >> temp;
}
cout << "Is it windy? enter Y for yes and N for no";
cin >> windy;
while ((windy != 'Y') || (windy != 'N'))
{
cout << " Invalid entry !!! Please enter Y or N";
cin >> windy;
}
// decisions & output
//If the temperature is less than 0 degrees tell the user to stay home .
if (temp < 0)
{
cout << " Stay Home !!" << endl << endl;
}
//If it is less than 20 degrees, tell them to wear a heavy coat.
elseif (temp >= 0 && temp < 20)
{
cout << " Wear a heavy coat !!" << endl << endl;
}
//If it is less than 45 degrees tell them to wear a coat.
elseif (temp >= 20 && temp < 45)
{
cout << " Wear a coat" << endl << endl;
}
elseif (temp >= 45 && temp < 70)
//If it is less than 70 degrees,tell them to wear a jacket
{
cout << " Wear a jacket ! " << endl << endl;
}
elseif (temp > 70 && windy == 'Y')
///If it is greater than 70 degrees, amd windy tell them to wear a jacket
{
cout << "Wear a jacket ! " << endl << endl;
}
else
//Otherwise, tell them that they do not need a jacket.
{
cout << "You do not need a jacket." << endl << endl;
}
system("pause");
return 0;
}
This will alway result in "true". Do you see why?
If windy == 'Y', it will result in (false || true), which is true.
If windy == 'N', it will result in (true || false), which is true.
If windy == 'X', it will result in (true || true), which is true.
You want &&, not ||.
windy doesn't equal Y AND windy doesn't equal N.