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
|
/*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;
}
|