1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
//Matthew Beard
//Program 3
#include <iostream>
#include <iomanip>
using namespace std;
//Functions
void showWelcome();
void showMenu();
void showSpring(float, float, float, float);
void showSummer(float, float, float, float);
void showFall(float, float, float, float);
void showWinter(float, float, float, float);
int main()
{
int choice; //menu choice
float spring, spring1, spring2, spring3,
summer, summer1, summer2, summer3,
fall, fall1, fall2, fall3,
winter, winter1, winter2, winter3;
//constants for menu choices
const int SPRING_CHOICE = 1,
SUMMER_CHOICE = 2,
FALL_CHOICE = 3,
WINTER_CHOICE = 4,
QUIT_CHOICE = 5;
cout << fixed << showpoint << setprecision(1); //sets to 1 decimal place
do
{
showWelcome(); // Show Welcome screen
showMenu(); // Display Menu
cin >> choice;
//Validate menu selection
while (choice < SPRING_CHOICE || choice > QUIT_CHOICE)
{
cout << "Please enter a valid menu choice: ";
cin >> choice;
}
//If user does not want to quit, proceed.
if (choice != QUIT_CHOICE)
{
switch (choice)
{
case SPRING_CHOICE:
showSpring(spring, spring1, spring2, spring3);
break;
case SUMMER_CHOICE:
showSummer(summer, summer1, summer2, summer3);
break;
case FALL_CHOICE:
showFall(fall, fall1, fall2, fall3);
break;
case WINTER_CHOICE:
showWinter(winter, winter1, winter2, winter3);
break;
}
}
} while (choice != QUIT_CHOICE);
return 0;
}
//Welcome Function
void showWelcome()
{
cout << "Welcome to the average rainfall calculator" << endl << endl;
system ("pause");
}
//Menu Function
void showMenu()
{
cout << "Please choose a season" << endl << endl
<< "1. Spring" << endl
<< "2. Summer" << endl
<< "3. Fall" << endl
<< "4. Winter"<< endl
<< "5. Quit" << endl << endl;
}
//Spring choice function
void showSpring(float spring, float spring1, float spring2, float spring3)
{
cout << "Enter the rainfall for month one " << endl;
cin >> spring1;
cout << endl << "Enter the rainfall for month two " << endl;
cin >> spring2;
cout << endl << "Enter the rainfall for month three " << endl;
cin >> spring3;
spring = (spring1 + spring2 + spring3) / 3;
cout << endl << "The average rainfall for Spring was "
<< spring << endl << endl;
}
//Summer choice function
void showSummer(float summer, float summer1, float summer2, float summer3)
{
cout << endl << "Enter the rainfall for month one " << endl;
cin >> summer1;
cout << endl << "Enter the rainfall for month two " << endl;
cin >> summer2;
cout << endl << "Enter the rainfall for month three " << endl;
cin >> summer3;
summer = (summer1 + summer2 + summer3) / 3;
cout << endl << "The the average rainfall for Summer was "
<< summer << endl << endl;
}
//Fall choice function
void showFall(float fall, float fall1, float fall2, float fall3)
{
cout << endl << "Enter the rainfall for month one " << endl;
cin >> fall1;
cout << endl << "Enter the rainfall for month two " << endl;
cin >> fall2;
cout << endl << "Enter the rainfall for month three " << endl;
cin >> fall3;
fall = (fall1 + fall2 + fall3) / 3;
cout << endl << "The average rainfall for Fall was "
<< fall << endl << endl;
}
//Winter choice function
void showWinter(float winter, float winter1, float winter2, float winter3)
{
cout << endl << "Enter the rainfall for month one " << endl;
cin >> winter1;
cout << endl << "Enter the rainfall for month two " << endl;
cin >> winter2;
cout << endl << "Enter the rainfall for month three " << endl;
cin >> winter3;
winter = (winter1 + winter2 + winter3) / 3;
cout << endl << "The average rainfall for Winter was "
<< winter << endl << endl;
}
|