You are running a camp and must decide what activities to schedule. You decide t
ID: 3790499 • Letter: Y
Question
You are running a camp and must decide what activities to schedule. You decide to base the decision on the temperature measured in degrees Fahrenheit. If the temperature is above 85°, you schedule swimming. If the temperature is above 70° and less than or equal to 85°, you schedule baseball. If the temperature is above 32° and less than or equal to 70°, you schedule basketball. Finally, if the temperature is below 32°, you send everyone home. Create a program that takes the temperatures as input and provides as output your sports decision. (Assume that temperatures are only expressed as integers.) In the program include 2 void functions titled getTemp and printActivity, each with an int argument. The function getTemp should have a Reference parameter that gets the temperature in getTemp and then passes the value back to be printed in main( ), and printActivity should have a Value parameter. The function getTemp should prompt the user for the temperature in Fahrenheit, get the input from the user, and return to main( ) where it prints the temperature on the screen. The function printActivity should determine the activity and print it as output on the screen. (Be careful and note that this problem requires you to input the temperature into getTemp and not directly into the main function.)
Explanation / Answer
#include <iostream>
using namespace std;
void getTemp(int &temp){
cout<<"Enter the temperature in Fahrenheit: ";
cin >> temp;
}
void printActivity (int temp){
if( temp > 70 && temp <=85){
cout<<"you schedule baseball"<<endl;
}
else if( temp >= 32 && temp <=70){
cout<<"you schedule basketball"<<endl;
}
else{
cout<<"you send everyone home"<<endl;
}
}
int main()
{
int temp;
getTemp(temp);
printActivity(temp);
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the temperature in Fahrenheit: 66
you schedule basketball
sh-4.2$ main
Enter the temperature in Fahrenheit: 84
you schedule baseball
sh-4.2$ main
Enter the temperature in Fahrenheit: 22
you send everyone home
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.