| Functions Worksheet #5 |
Name - |
| |
Day of Week - |
Draw the output window with the expected output as precisely as possible. Assume that the user enters the values 3 and 4.
#include <iostream>
using namespace std;
void displayMenu();
void displayPrice(int num);
double computeTotal(int number, int num);
int main()
{
int quantity = 0;
int choice = 0;
displayMenu();
cout << "Enter choice: ";
cin >> choice;
displayPrice(choice);
cout << "How many would you like to buy: ";
cin >> quantity;
cout << "You owe $" << computeTotal(quantity, choice) << endl;
return 0;
}// end of main
void displayMenu()
{
cout << "1. apples" << endl;
cout << "2. bananas" << endl;
cout << "3. carrots" << endl;
}// end of displayMenu
void displayPrice(int num)
{
if (num == 1)
cout << "The price of an apple is $1" << endl;
else if (num == 2)
cout << "The price of a banana is $2" << endl;
else
cout << "The price of a carrot is $3" << endl;
}// end of displayPrice
double computeTotal(int number, int num)
{
if (num == 1)
return 1 * number;
else if (num == 2)
return 2 * number;
else
return 3 * number;
}// end of computeTotal