Question

In: Computer Science

Language C++ Most people know that the average human body temperature is 98.6 Fahrenheit (F). However,...

Language C++

Most people know that the average human body temperature is 98.6 Fahrenheit (F). However, body temperatures can reach extreme levels, at which point the person will likely become unconscious (or worse). Those extremes are at or below 86 F and at or above 106 F.

Write a program that asks the user for a body temperature in Fahrenheit (decimals are ok). Check if that temperature is in the danger zone (for unconsciousness) or not and produce the relevant output shown below. Also check if the user entered a number greater than zero. If they didn't, display an error message and don't process the rest of this program.

If the entry was valid, convert the temperature from Fahrenheit to Celsius. and output it to the user.

F to C formula: (temp - 32) * 5 / 9

Prompts:

Enter a body temperature in Fahrenheit: [possible user input: 107]

Possible Outputs:

This person is likely unconscious and in danger
Temperature in Celsius is: 41.6667

This person is likely conscious
Temperature in Celsius is: 37

Invalid entry

Notes and Hints:

1) This exercise is testing your knowledge of Flags and Logical Operators. Use both!

2) Do not use constants for the numbers in the F to C formula. Write it as-is.

3) Hint: The order in which you do your decision/conditional statements makes all the difference

4) Remember: Do not let this program do any math if the user's entry is invalid!

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
int main(){
    //initializing Celsius and Fahrenheit temperature
    double c,f;
    //asking for Fahrenheit temperature
    cout<<"Enter a body temperature in Fahrenheit: ";
    //accepting it
    cin>>f;
    //initializing flag as False
    bool flag=true;
    //checking if temperature is less than or equal to 0
    if(f<=0){
        //setting flag as false
        flag=false;
    }
    //checking if flag is true
    if(flag){
        //checking if Temperature is less than or equal to 86 or greater than or equal to 106
        if(f<=86 || f>=106)
            //printing unconscious and in danger
            cout<<"This person is likely unconscious and in danger"<<endl;
        else
        //printing conscious
            cout<<"This person is likely conscious"<<endl;
        //finding Celsius Temperature
        c=(f-32)*5.0/9.0;
        //printing it
        cout<<"Temperature in Celsius is: "<<c<<endl;
    }
    else
    //printint Invalid entry
        cout<<"Invalid entry"<<endl;
    return 0;
}

Screenshot:


Input and Output:


Related Solutions

The average body temperature for healthy adults is 98.6 °F. Is this statement true? Do all...
The average body temperature for healthy adults is 98.6 °F. Is this statement true? Do all healthy people have exactly the same body temperature? A study was conducted a few years go to examine this belief. The body temperatures of n = 130 healthy adults were measured (half male and half female). The average temperature from the sample was found to be x̄ = 98.249 with standard deviation s = 0.7332. Do these statistics contradict the belief that the average...
It is commonly believed that the mean body temperature of a healthy adult is 98.6 F....
It is commonly believed that the mean body temperature of a healthy adult is 98.6 F. You are not entirely convinced. You collected data using 43 healthy people and found that they had a mean body temperature of 98.21 F with a standard deviation of 1.14 F. Use a 0.05 significance level to test the claim that the mean body temperature of a healthy adult is not 98.6 F. Please do not use a table, use calculator.
The body temperature of adults is normally distributed with a mean of 98.6°F and standard deviation...
The body temperature of adults is normally distributed with a mean of 98.6°F and standard deviation of 0.60°F. Suppose 36 adults are randomly selected, what is the probability that their mean body temperature is less than 98.0°F?
It has long been stated that the mean temperature of humans is 98.6 degrees F. ​However,...
It has long been stated that the mean temperature of humans is 98.6 degrees F. ​However, two researchers currently involved in the subject thought that the mean temperature of humans is less than 98.6 degrees F. They measured the temperatures of 44 healthy adults 1 to 4 times daily for 3​ days, obtaining 200 measurements. The sample data resulted in a sample mean of 98.3 degrees F and a sample standard deviation of 1 degrees F. Use the​ P-value approach...
It is commonly believed that the mean body temperature of a healthy adult is 98.6∘F98.6∘F. You...
It is commonly believed that the mean body temperature of a healthy adult is 98.6∘F98.6∘F. You are not entirely convinced. You believe that it is not 98.6∘F98.6∘F. You collected data using 51 healthy people and found that they had a mean body temperature of 98.2∘F98.2∘F with a standard deviation of 1.18∘F1.18∘F. Use a 0.05 significance level to test the claim that the mean body temperature of a healthy adult is not 98.6∘F98.6∘F. a) Identify the null and alternative hypotheses? b)...
Have everyone in class take his or her temperature on a healthy day. Test the claim that the median body temperature is 98.6 F.
Have everyone in class take his or her temperature on a healthy day. Test the claim that the median body temperature is 98.6F.
2) Human Body Temperature. A sample of 112 body temperatures with a mean of 98.20°F and...
2) Human Body Temperature. A sample of 112 body temperatures with a mean of 98.20°F and a standard deviation of 0.62°F. Use a 0.05 significance level to test the claim that the mean body temperature of the population is equal to 99.6°F, as is commonly believed. Is there sufficient evidence to conclude that the common belief wrong?
The body temperatures of adults are normally distributed with a mean of 98.6° F and a...
The body temperatures of adults are normally distributed with a mean of 98.6° F and a standard deviation of 0.50° F. If 25 adults are randomly selected, find the probability that their mean body temperature is greater than 98.4° F.
1. Temperature in kelvins (K) is related to the temperature in degrees Fahrenheit (°F) by the...
1. Temperature in kelvins (K) is related to the temperature in degrees Fahrenheit (°F) by the equation Design a MATLAB program that will do the following a. Prompt the user to enter an input temperature in °F. b. Read the input temperature. c. Calculate the temperature in kelvins in a separate function d. Write out the results with two digits to the right of the decimal (Use the fprintf function). The results should go to the command window.
The body temperatures of adults have a mean of 98.6° F and a standard deviation of...
The body temperatures of adults have a mean of 98.6° F and a standard deviation of 0.60° F. If 36 adults are randomly selected, find the probability that their mean body temperature is greater than 98.8° F. Hint: You will need to use the sampling distribution of the sample mean. 0.8188 0.9772 0.9360 0.0228
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT