1.A student with a temperature from 36.5°C to 37°C will be allowed to write their exams. The value of the students’ temperature will be stored in variable called temperature.
1.1 Write a C++ while clause that will allow the program to execute when the value in the temperature variable is within the required range.
1.2 Which data type of data is the student’s temperature.
SOLUTION TO THE ABOVE QUESTION
1.1 Write a C++ while clause that will allow the program to execute when the value in the temperature variable is within the required range.
ANSWER(A PROGRAM)
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
//declare a variable named temperature of float type to store the temperature of a student
float temperature;
//propmt the user to enter the temperature of a student
cout<<"\n\tPlease enter the temperature of the student in degrees celcius: ";
cin>>temperature;
//definition of a while clause
//The while clause will only terminate when the value of temperature entered is not within the range
while(temperature>=36.5 && temperature<=37)
{
cout<<"\n\tThe student is eligible to sit for the exams"<<endl;
//propmt the user to enter the temperature agian
cout<<"\n\tPlease enter the temperature of the student in degrees celcius: ";
cin>>temperature;
//if temperature is not within the range display exit message
if(!(temperature>=36.5 && temperature<=37))
{
cout<<"\n\tThe student entered is not eligible to write the exams"<<endl;
cout<<"\n\tThe program has been exited"<<endl;
}
}
return 0;
}
1.2 Which data type of data is the student’s temperature.
ANSWER.
variable temperature is of float type.
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment