assignment assistance

I have an assignment due soon and I'm having trouble with some of the functionality. Basically, this menu is dictated by switch cases containing functions that return values that will be used in a final computation.

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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Programmer: Chase Simpson
// Instructor: Price / A
// Date: 10/02/16
// Purpose: Compute individuals 'carbon footprint' in order to better the environment of Springfield.

#include <iostream>
using namespace std;

//Function Prototypes
/* Defintion: Outputs a greeting to screen on program start.
 * Pre: None
 * Post: Greeting is output to screen. */
void outputGreeting();

/* Definition: Prompts user for input of food wasted daily.
 * Pre: ??
 * Post: User inputs integer between 0 and 100.*/
 float poundsFood();
 
 /* Definition: Prompts user for whether or not they use public transit, if so
  * 	how many miles?
  * Pre: ??
  * Post: User inputs answer and appropriate value is returned.*/
  int publicTransit();
  
  /*Definition: Prompts user for wether or not they are Mr. Burns, are
   * 	related to Mr. Burns, or their age.
   * Pre: ??
   * Post: Value is returned based on user's input. */
   int burnsCheck();
   
   /*Definition: Checks if user has selected option 1, if they have, prompts for
    * 		input of whole pigs eaten that week.
    * Pre: Values are valid and modifiable.
    * Post: Compute value and return. */
   float methaneProduction(int wastedFood);
   
   /*Definition: Displays sign off message to user at end of program.
    * Pre: None
    * Post: Sign off message is output to screen signaling program termination. */
    void outputSignOff();
   
   const int MAX_CHOICE = 100;
   const int MIN_CHOICE = 10;
   const int MAX_MILES = 250;
   const int MIN_MILES = 1;
   const int BURNS_COEFFICIENT = 570;
   const int HALF = 2;
   bool UsageCheck_1 = false;
   

int main()
{
	
int choice;
float wastedFood;
float methaneProduced;

//Display Menu and Get User Input
	do
	 {
		 cout<<"  Carbon Footprint Survey  "<<endl
				<<"---------------------------------"<<endl
				<<"1. Wasteful (food) Consumption"<<endl
				<<"2. Public Transit Use"<<endl
				<<"3. Industrial Complicity"<<endl
				<<"4. Farm-related Methane Production"<<endl
				<<"5. Compute GUILT Value"<<endl;
		
		 cout<<"Please choose an option from the menu above: ";
		    	cin>>choice;
		    switch(choice)
		    {
				case 1: 
				   wastedFood = poundsFood();
				   usageCheck_1 = true;
				break;
				
				case 2:
                   publicTransit();
                   				
				break;
				
				case 3:
				   burnsCheck();
				   
				break;
				
				case 4:
				  methaneProduced = methaneProduction(float wastedFood);
				   
				break;
				
				case 5:
				
				break;
				
				default:
					cout<<"Choose an item between 1 and 5."<<endl;
			}
		} while (choice != 5);

// Sign Off Message
outputSignOff();

return 0;
}

//Function Definitions

 void outputGreeting()
 {
	 cout<<"Welcome to Carbon Footprint detection program!"<<endl;
}

float poundsFood()
{
	 float foodWasted = 0;
	   cout<<"Enter the amount of food wasted daily, in pounds: ";
	      cin>>foodWasted;
	      
	   if (foodWasted > MAX_CHOICE)
	    {
			cout<<"Invalid input, enter a number between 0 and 100: ";
				cin>>foodWasted;
		}
	   else if (foodWasted < MIN_CHOICE)
	    {
	        cout<<"Invalid input, enter a number between 0 and 100: ";
				cin>>foodWasted;
		}
	return foodWasted;
}

int publicTransit()
{
	bool answer;
	float dailyMiles;
	
	cout<<"Do you use public transit? 1=Yes, 0=No  "<<endl;
		cin>>answer;
	if(answer==0)
	{
		dailyMiles = 0;
		return dailyMiles;
	}
	else
	{
		cout<<"How many miles do you travel on public transit daily? ";
			cin>>dailyMiles;
	}
	if (dailyMiles > MAX_MILES)
	{
		cout<<"Invalid input, enter a number between 1 and 250: ";
			cin>>dailyMiles;
	}
	else if (dailyMiles < MIN_MILES)
	{
		cout<<"Invalid input, enter a number between 1 and 250: ";
			cin>>dailyMiles;
	}
	return dailyMiles;
}

int burnsCheck()
{
	char areYouBurns;
	int destructionCoefficient;
	int age;
	
		cout<<"Are you Mr. Burns? Y/N? ";
			cin>>areYouBurns;
			
		if(areYouBurns == 'Y')
        {
			destructionCoefficient = BURNS_COEFFICIENT;
			return destructionCoefficient;
		}
		else if(areYouBurns == 'N')
		{
			cout<<"Are you related to Mr. Burns? ";
				cin>>areYouBurns;
		}
		if(areYouBurns == 'Y')
		{
			destructionCoefficient = (BURNS_COEFFICIENT / HALF);
			return destructionCoefficient;
		}
		else if (areYouBurns == 'N')
		{
			cout<<"Thank god! Enter your age: ";
				cin>>age;
				return age;
		}
		return age;
	
}

float methaneProduction(float wastedFood)
{
	int pigsEaten;
	float gasProduction;
	
	if (usageCheck_1 = true)
		cout<<"Enter the number of whole pigs consumed by your "
				<<"father this week: ";
					cin>>pigsEaten;
					
			gasProduction = (wastedFood * (pigsEaten * pigsEaten) + 3) *
									(pigsEaten + 5);
									
			return gasProduction;
			
	else if (usageCheck_1 = false)
	
		cout<<"You must select option 1 before this option is available."<<endl;
 
}

void outputSignOff()
{
	cout<<"Thanks for using the Carbon Footprint detection program!"<<endl;
	cout<<"Have a great day!"<<endl;
}


I'm getting compiling errors with all statements containing usageCheck_1, I made this variable to attempt to make it so that case 4 may not be chosen before option 1 has been chosen. I also need to make the program so that option 5 cannot be chosen until options 1-4 have been chosen, can somebody help me with this? I'm sorry this is so vague I'm in a hurry. =/
Last edited on
What is/are your exact compiler error(s)?
1.
204
205
if (usageCheck_1 = true)
cout<<"Enter the number of whole pigs consumed by your "


Shoul be :
204
205
if (usageCheck_1 == true)
cout<<"Enter the number of whole pigs consumed by your "


2.
214
215
if (usageCheck_1 = false)
cout<<"You must select option 1 before this option is available."<<endl;


Should be :
214
215
if (usageCheck_1 == false)
cout<<"You must select option 1 before this option is available."<<endl;


Last edited on
Topic archived. No new replies allowed.