Write a program takes temperature readings, but fails if the temperature value
goes out of range three times. Output the average so we know what a stable
temperature is for these reagents.
You should repeatedly ask the user for input until the temperature value
goes outside the following range [22,230]. If the temperature values goes outside
the range, output a warning the first two times and an error the last time.
Here are the functions you should write:
calcAvg - this should calculate the average value of the readings, not including
the three out of range values.
displayWarning - this should display a warning,
use a global variable to tell the user if it's the first or last warning.
displayError - this should display an error, it should only be called when
exiting the program if we got three bad readings.
GetReading - this should return a boolean value, and
store the temperature entered by the user in the input parameter.
It should return true if there was
a successful reading or false if the reading was out of range.
If at any time the user wants to stop entering temperature readings,
they should type -123456.
Finally, you should output the decimal average with exactly 2 decimal places.
Maybe you can have an int, and initialize it to 0 or 1. Then anytime the user enters a value out of range, increase the int by one(1).
Check for the value of the int. If it is less than three(3), cout a warning but if it is greater or equal to three(3), then cout an error.
int i=0; //the int I was referring to in my last post to do the checking
int iInput; //for user input purposes
cout<<"Type the integer one(1): ";
i++; //increases if user did not follow my autocratic rule
if(i<3) //the warning. this condition is met twice if you analyze
cout<<"\nJust obey! I said the number one!";
elseif(i>=3) //finally, the error. this condition is met after two warnings
cout<<"\nYou are toooooo disobedient.\nI'm exiting!!!";
Is what I've got so far. What's making this assignment so confusing is the fact that usually we'll be told what the console looks like, or at least what the functions look like. This time around it seems as though my professor decided to take off the training wheels, and thus why I'm having so much trouble with this.
At this point, I don't know where to input the loop so that the program keeps asking the user for the input if it's between the aforementioned parameters.
GetReading needs the modification of the parameter InputTemp to be propagated to the calling code, so the parameter should be of type reference to int.
Since GetReading returns a boolean value indicating whether or not a successful reading was taken (and, thus whether the program should continue getting further readings) I imagine you'll want to loop on the return value of GetReading in the code that calls it.
bool GetReading( int& reading )
for ( ;; )
get user input for reading.
if ( user input is the sentinel to stop getting input )
returnfalseelseif ( user input is outside the proscribed ranges )
if ( this is not the third invalid input )
display a warning
display an error
Sometimes it helps to consider the logic before you start writing code.