When the user enters "cot" and then enters 53.8 as the temperature, the code returns the 'Temp is too low' even though it's a valid temperature. I've played with changing the number in the determining if-statement up and down, but 53.8 is the only number that gives me this error.
Issue is in the second while loop in the main function where it sends the objTemp to the inValid Temp function (second to last function in code).
A user would first be prompted for a strange object and enter "cot", then enter "53.8" when prompted for the object's temperature afterwards.
I know I could change this around to get it to work, but I'm learning and really want to understand what's going on.
Any ideas?
//Ask for temperature of obj. in Fahrenheit
cout << "Enter the " << inString << "'s temperature in Fahrenheit." << endl;
cin >> objTemp;
//Validate range| loop again until valid entry is made.
while ((validRange = invalidTemp(objIs, objTemp = 53.8)))
{
if (validRange == 1)
cout << "Entered temperature is too low.\n";
else
cout << "Entered temperature is too high.\n";
cout << "Enter the " << inString << "'s temperature in Fahrenheit." << endl;
cin >> objTemp;
}
//Choose from conversion menu|| User enters selection, and menu returns appropriate conversion factor
convMenu(objTemp);
//insert program pause
return 0;
}
int invalidTemp(int object, float inTemp)
{
switch(object)
{
case 1: if (inTemp < 85.8) //temp for cat
return 1;
else if (inTemp > 102.2)
return 2;
break;
case 2: if (inTemp < 53.8) //temp for cot
return 1;
else if (inTemp > 80.2)
return 2;
break;
case 3: if (inTemp < 71.8) //temp for cap
return 1;
else if (inTemp > 88.2)
return 2;
break;
case 4: if (inTemp < 90.8) // temp for snake
return 1;
else if (inTemp > 100.2)
return 2;
break;
//default: cout << "Valid" << endl;
}
return 0;
}