|
-
April 27th, 2017, 10:24 AM
#1
Overload function error
Now I just have issue figuring out how to add the quantities, as in if I make the same selection more than once it only calculates one.
Code:
//
//Preprocessor Directives
#include <iostream>
#include <string>
#include <iomanip>
#include <string>
using namespace std;
//Menu Structure
struct menuOptions
{
int quantity;
double price;
string description;
};
//prototype
void displayMenu(menuOptions menu[], int size);
void getData(menuOptions menu[], int &size);
void printCheck(menuOptions menu[], int size);
//constants
const int max = 8;
const double taxes = 0.05;
// main function
int main()
{
menuOptions menu[max];
int size = 0;
getData(menu, size);
displayMenu(menu, size);
printCheck(menu, size);
system("pause");
// exit main
return 0;
}
//getting the data in to array
void getData(menuOptions menu[], int &size)
{
menu[0].description = "Plain Egg"; menu[0].price = 1.45; menu[0].quantity = 0;
menu[1].description = "Bacon and Egg"; menu[1].price = 2.45; menu[1].quantity = 0;
menu[2].description = "Muffin"; menu[2].price = 0.99; menu[2].quantity = 0;
menu[3].description = "French Toast"; menu[3].price = 1.99; menu[3].quantity = 0;
menu[4].description = "Fruit Basket"; menu[4].price = 2.49; menu[4].quantity = 0;
menu[5].description = "Cereal"; menu[5].price = 0.69; menu[5].quantity = 0;
menu[6].description = "Coffee"; menu[6].price = 0.50; menu[6].quantity = 0;
menu[7].description = "Tea"; menu[7].price = 0.75; menu[7].quantity = 0;
size = 8;
}
//display menu and tell user what to do
void displayMenu(menuOptions menu[], int size)
{
cout << "Welcome to Johnny's Restaurant" << endl;
cout << setw(20) << "Johnny's Menu" << endl;
for (int i = 0; i < size; i++)
{
cout << (i + 1) << ". " << left << setw(21) << menu[i].description << "$" << setw(6) << setprecision(2) << fixed << menu[i].price << endl;
}
cout << "------------------------------" << endl;
int number;
int quantity;
cout << "\nSelect your item 1-8. Press 9 when you are finished: ";
cin >> number;
while (number != 9)
{
if (number >= 1 && number <= 8)
{
menu[number -1].quantity = 1;
}
else
{
cout << "Invalid Option! Item selection 1-8, and press 9 to finish your order!" << endl;
}
cout << "Select your item 1-8. Press 9 when you are finished: ";
cin >> number;
}
}
//calc and print check
void printCheck(menuOptions menu[], int size)
{
double totalPrice = 0;
double totalTax = 0;
cout << "\nYour Check is:" << endl;
cout << endl << "Welcome to Johnny's Restaurant" << endl;
for (int i = 0; i < size; i++)
{
if (menu[i].quantity > 0)
{
cout << left << setw(2) <<menu[i].quantity <<setw(22) << menu[i].description << "$" << setw(12) << setprecision(2) << fixed << menu[i].price << endl;
totalPrice += menu[i].price;
}
}
totalTax = totalPrice * taxes;
cout << setw(24) << "Tax:" << "$" << setw(14) << setprecision(2) << fixed << totalTax << endl;
cout << setw(24) << "Amount Due:" << "$" << setw(14) << setprecision(2) << fixed << (totalPrice + totalTax) << endl << endl;
}
}
Last edited by TheJollyRoger; April 28th, 2017 at 01:22 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|