diff options
| author | till-t <[email protected]> | 2021-11-02 21:43:39 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-02 21:43:39 -0700 |
| commit | fd63ba58b9cb3a063d4c13fd99402c3b6af9ed10 (patch) | |
| tree | 060842a2f886324e2d877a79a4fde90a1325a25f | |
| parent | Completed Lab 3 (diff) | |
| download | cst116-lab3-till-t-master.tar.xz cst116-lab3-till-t-master.zip | |
| -rw-r--r-- | main.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..587c734 --- /dev/null +++ b/main.cpp @@ -0,0 +1,135 @@ +/*Tyler Taormina + * Midterm challenge + * + * Description: For the midterm challenge I decided to build a simple calculator + * that displays an estimated yearly cost of dog food based on a few factors + * that the user provides. These factors are the size of the dog and the type of + * food that the owner would prefer to feed their dog. The two choices of dog + * food are 'organic' and 'regular'. Code and Run included. + * + */ + + +#include <iostream> +using namespace std; + +int main(); +void yearlyCost (int, float, float&, int); +void dogInfo(int&); +void foodInfo(int&); +void determine_servings(int, float&); +void bagsPerWeek (int, float, float&); +void display(float); +int main() +{ + + int const WEEKS = 56; //weeks in a year + int const DAYS = 7; //days per week + int const SERVING_PER_BAG = 20; + float const ORG=29.99, REG=19.99; + int dog=0; + float day_servings=0; + int foodType=0; + float weekly_portion=0.0; + float cost=0.0; + float total_cost=0.0; + + dogInfo(dog); + determine_servings(dog, day_servings); + foodInfo(foodType); + bagsPerWeek(DAYS, day_servings, weekly_portion); + yearlyCost(WEEKS, weekly_portion, total_cost, foodType); + display(total_cost); + + return 0; +} + +void dogInfo(int& dog) +{ + cout << "\n\nThis program will help you determine the yearly cost of dog food." << endl; + cout << "First, we will ask you a few questions!" << endl; + cout << "******************************************************************\n\n" << endl; + cout << "What size dog do you have?\n\n" << endl; + cout << "Press 1 for a small dog." << endl; + cout << "Press 2 for a medium dog." << endl; + cout << "Press 3 for a large dog." << endl; + cout << "Press 4 if you are unsure." << endl; + cin >> dog; +} + +void foodInfo(int& foodType) +{ + cout << "\n\nLets talk about Dog food for a moment." << endl; + cout << "******************************************************************\n\n" << endl; + cout << "What kind of dog food would you prefer. Organic or Original?\n\n" << endl; + cout << "Enter 1 for Organic." << endl; + cout << "Enter 2 for Original." << endl; + cin >> foodType; + + if (foodType > 2 || foodType < 1) + { + cout << "\n\nSorry. These are the only food choices we offer.\n"; + cout << "Please reenter your food choice."; + foodInfo(foodType); + } +} + +void determine_servings(int dog, float& day_servings) +{ + switch (dog) { + // small dog + case 1: + day_servings = 1; + break; + + case 2: + day_servings = 1.5; + break; + + case 3: + day_servings = 2; + break; + + case 4: + cout << "\n\nGenerally a small dog is a dog that weighs under 20lbs.\n"; + cout << " A medium dog weighs anywhere from 20lbs to 50lbs and\n"; + cout << " a large dog would weigh over 50lbs. Hope this helps\n"; + cout << " in determining the correct size for your dog. Lets\n"; + cout << " try again!" << endl; + main(); + + default: + cout << "WHOOPS! INVALID ENTRY. PLEASE TRY AGAIN." << endl; + main(); + } +} + + +void bagsPerWeek(int DAYS, float day_servings, float& weekly_portion) +{ + weekly_portion = (day_servings * DAYS) / 7; +} + +void yearlyCost(int WEEKS, float weekly_portion, float& total_cost, int foodType) +{ + float yearly_bags = 0.0; + float const ORG=29.99, REG=19.99; + + yearly_bags = weekly_portion * WEEKS; + + if (foodType == 1) + total_cost = yearly_bags * ORG; + else + total_cost = yearly_bags * REG; + +} + +void display(float total_cost) +{ + cout << "\n\n\nBased on the information you have entered, here is what we came up with.\n\n\n"; + cout << "The estimated yearly cost of your dogs food is: $" << total_cost << endl; + cout << "Remember that this is estimation is based upon veterinary recommendations" << endl; + cout << "If your dog experiences any symptoms that you believe are related to diet,\n"; + cout << "immediately contact a veterinary clinic." << endl; + cout << "Thanks for participating!" << endl; +} |