Below I have put together a rough draft of my Menu for my final project. It looks to be okay but the program will not run. Any suggestions would be nice.
/*
APP/CPP/FOLDER: Ref_Menu_Elliott
This program uses a reference variable as a function
parameter.
INSTRUCTIONS: Type this code line by line first (with comments), then seek to solve
the various programming challenges herein.
Base code from Gaddis (2012).
Expanded by: Dr. Tyson McMillan, 10-18-2014
Updated by
Student: Christopher Elliott a.k.a. "Mamba Ki", 11-29-2016
A menu using the Power of functions that pass values by reference.
When a function uses pass by refrence, it can manipulate variable values outside
of its own scope. Reference refers to the memory location of the variable.
*/
#include <iostream>
#include <cstdlib> //to be able to use system("cls"); in multiple platforms
using namespace std;
// Function prototype. The parameter is a reference variable.
void doubleNum(int &);
void increaseNum(int &);
void decreaseNum(int &);
void displayMenu();
void displayPatterns();
int main()
{
setColor(10);
int value = 4;
cout << "In main, value is " << value << endl;
cout << "Now calling doubleNum..." << endl;
doubleNum(value);
cout << "Now back in main. value is " << value << endl;
//using the pass by reference premise on a C++ menu
cout << "\n\nLet's practice this premise on a C++ Menu" << endl;
displayMenu(); //function call
/*Programming Challenges
1) Add 4 more menu items to this program.
2) Validate input of decision
3) Display a custom Exit message when -9 inputted;
4) Add color to enhance messages to the user.
hint: much of this is done in the displayMenu() function definition
*/
//EXTRA Challenge: displayPatterns()
displayPatterns(); //see function definition below
return 0;
}
//**********************************************************
// Definition of doubleNum. *
// The parameter refVar is a reference variable. The value *
// in refVar is doubled. *
//**********************************************************
void doubleNum(int &refVar)
{
refVar *= 2;
}
void increaseNum(int &counter)
{
counter++;
}
void decreaseNum(int &counter)
{
counter--;
}
void displayMenu()
{
int mainDecision = 0;
int greenTeaCounter = 0;
int lobsterTailCounter =0;
int oatmealCookieCounter =0;
int kahunaSaladCounter =0;
int vinegarChipsCounter =0;
do
{
if(mainDecision == 0) //first run of the menu
{
cout << "\n************WELCOME TO MAMBA KI'S RESTAURANT!!!************" << endl;
}
//increment menu item
if(mainDecision == 1)
{
increaseNum(greenTeaCounter);
}
//increment menu item
if(mainDecision ==2)
{
increaseNum(lobsterTailCounter);
}
//increment menu item
if(mainDecision ==3)
{
increaseNum(oatmealCookieCounter);
}
//increment menu item
if(mainDecision ==4)
{
increaseNum(kahunaSaladCounter);
}
//increment menu item
if(mainDecision ==5)
{
increaseNum(vinegarChipsCounter);
}
//decrement menu item
if(mainDecision == -1)
{
if(greenTeaCounter != 0) //subtract only if value greather than 0
{
decreaseNum(greenTeaCounter);
}
else
{
cout << "Negative: Green Tea Order must be > 0 to ";
cout << "subtract (please try again)" << endl;
}
}
//decrement menu item
if(mainDecision == -2)
{
if(lobsterTailCounter != 0) //subtract only if value greather than 0
{
decreaseNum(lobsterTailCounter);
}
else
{
cout << "Negative: Lobster Tail Order must be > 0 to ";
cout << "subtract (please try again)" << endl;
}
}
//decrement menu item
if(mainDecision == -3)
{
if(oatmealCookieCounter != 0) //subtract only if value greather than 0
{
decreaseNum(oatmealCookieCounter);
}
else
{
cout << "Negative: Oatmeal Cookie Order must be > 0 to ";
cout << "subtract (please try again)" << endl;
}
}
//decrement menu item
if(mainDecision == -4)
{
if(kahunaSaladCounter != 0) //subtract only if value greather than 0
{
decreaseNum(kahunaSaladCounter);
}
else
{
cout << "Negative: Kahuna Salad Order must be > 0 to ";
cout << "subtract (please try again)" << endl;
}
}
//decrement menu item
if(mainDecision == -5)
{
if(vinegarChipsCounter != 0) //subtract only if value greather than 0
{
decreaseNum(vinegarChipsCounter);
}
else
{
cout << "Negative: Vinegar Chips Order must be > 0 to ";
cout << "subtract (please try again)" << endl;
}
}