CSC 118: Programming Fundamentals Lab 5: Programming assignment Programming assi
ID: 3726598 • Letter: C
Question
CSC 118: Programming Fundamentals Lab 5: Programming assignment Programming assignment 1 (If-then and if-then-else): Use the following shell program for this assignment // Progr Temperature reads in a temperature and prints an // appropriate message. #include using namespace std; int main ( int temperature; cout temperature * TO BE FILLED IN return 8 Exercise I: Add five if-then statements to program Temperature (temperature.cpp) so that one of the following messages is printed based on the value of temperature 90 90,> 80 80,> 70 Visit a neighbor Turn on air conditioning Do nothing Turn on heat Visit a neighbor Run your program as many times as it takes to display each message exactly once. Which data values did you use? Exercise 2: Rewrite the program in Exercise I using nested logic (ie. if-then-else where the else branch is an if statement). Rerun the program with the same data. Did you get the same answers? Explain. Turn in: Your answers and codes for Exercise 1 and Exercise2Explanation / Answer
1.
Please add this code
if ( temperature > 90)
{
cout << "Visit a neighbor " << endl;
}
if ( temperature >80 && temperature <=90)
{
cout << "Turn on air conditioning"<< endl;
}
if ( temperature >70 && temperature <=80)
{
cout << "Do nothing"<< endl;
}
if ( temperature >55 && temperature <=70)
{
cout << "Turn on heat"<< endl;
}
if ( temperature <=55)
{
cout << "Visit a neighbor"<< endl;
}
2.Please add this code
if ( temperature > 90)
{
cout << "Visit a neighbor " << endl;
}
else if ( temperature >80 && temperature <=90)
{
cout << "Turn on air consitioning"<< endl;
}
else if ( temperature >70 && temperature <=80)
{
cout << "Do nothing"<< endl;
}
else if ( temperature >55 && temperature <=70)
{
cout << "Turn on heat"<< endl;
}
else if ( temperature <=55)
{
cout << "Visit a neighbor"<< endl;
}