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.
// 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>
usingnamespace 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();
constint MAX_CHOICE = 100;
constint MIN_CHOICE = 10;
constint MAX_MILES = 250;
constint MIN_MILES = 1;
constint BURNS_COEFFICIENT = 570;
constint 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;
}
elseif (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;
}
elseif (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;
}
elseif(areYouBurns == 'N')
{
cout<<"Are you related to Mr. Burns? ";
cin>>areYouBurns;
}
if(areYouBurns == 'Y')
{
destructionCoefficient = (BURNS_COEFFICIENT / HALF);
return destructionCoefficient;
}
elseif (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;
elseif (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. =/