I am writing a program, I have everything setup, and I am needing help calling my void functions into main that would allow me to fill out the order and print a receipt.
I need my code to display like this picture, but I'm currently stuck on getting the menu to read in the order and print a reciept.
How my code needs to appear: https://gyazo.com/8f669a6c6bf15f8d147fbbbf71d4774a
This is the current code I have is:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void pMenu(string products[], double money[], int count, int
Order[]){
cout << endl;
cout << "Here is the menu." << endl;
for( int i = 0;i<count; i++){
cout << "How many "<< products[i] << " ("<<
money[i] << ")" << " do you want? ";
cin >> Order[i];
}
}
void receipt (string products[], float money[], int count, int
Order[]){
double r, tax;
int s = 0;
cout << endl;
cout << "Here is your RECEIPT: " << endl;
for( int i = 0; i < count; i++){
cout << right << setw(20) << fixed <<
products[i] << ": ";
if (Order[i] == 0){
cout << "NONE" << endl;
}
else {
cout << right << setw(4) << fixed <<
Order[i] <<" at $ " << money[i] << " = $ "
<< Order[i] * money[i] << endl;
r += Order[i] * money[i];
s += Order[i];
}
tax = r * .08;
}
cout << "TOTAL" << right << setw(36) <<
fixed << "$ " << r << endl;
cout << "TAX (8.0%)" << right << setw(31)
<< fixed << "$ " << tax << endl;
cout << "=============================================="
<< endl;
cout << "GRAND TOTAL" << right << setw(14)
<< fixed << s << " items"
<< right << setw(10) << fixed << "$ "
<< tax + r << endl;
}
int main(){
string menus;
int Order;
int count = 0;
char choice;
string product;
double price;
const int Maxsize = 20;
string products[Maxsize];
double money[Maxsize];
ifstream fileIn;
cout << "Welcome to Fredrick's Fast Foods
Reloaded!"<<endl;
cout << "Which menu would you like Normal or Kids? (N or K)
";
cin >> choice;
choice = toupper(choice);
if (choice == 'K'){
cout << "Here is the kids menu: " << endl;
fileIn.open("kids_menu.txt");
} else if(choice == 'N') {
cout << "Here is the normal menu: " << endl;
fileIn.open("normal_menu.txt");
} else{
cout << "Menu selection is invalid";
}
while(fileIn){
getline(fileIn, product, ',');
fileIn >> price;
products[count] = product;
money[count] = price;
cout << fixed << setprecision(2);
cout << product << " : $" << price <<
endl;
count++;
fileIn.get();
}
cout << "Please enter your order..." << endl;
}
Changes required to execute it properly.
1. Change the datatype of Order to array of integers in main method.
2. Call pMenu method at the end of code and before receipt method.
3. Call receipt method at the end of code.
4. Change the passed argument datatype of money to double.
Here is the output code. Please take a look.
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void pMenu(string products[], double money[], int count, int
Order[]){
cout << endl;
cout << "Here is the menu." << endl;
for( int i = 0;i<count; i++){
cout << "How many "<< products[i] << " ("<<
money[i] << ")" << " do you want? ";
cin >> Order[i];
}
}
void receipt (string products[], double money[],
int count, int Order[]){
double r, tax;
int s = 0;
cout << endl;
cout << "Here is your RECEIPT: " << endl;
for( int i = 0; i < count; i++){
cout << right << setw(20) << fixed <<
products[i] << ": ";
if (Order[i] == 0){
cout << "NONE" << endl;
}
else {
cout << right << setw(4) << fixed <<
Order[i] <<" at $ " << money[i] << " = $ "
<< Order[i] * money[i] << endl;
r += Order[i] * money[i];
s += Order[i];
}
tax = r * .08;
}
cout << "TOTAL" << right << setw(36) <<
fixed << "$ " << r << endl;
cout << "TAX (8.0%)" << right << setw(31)
<< fixed << "$ " << tax << endl;
cout << "=============================================="
<< endl;
cout << "GRAND TOTAL" << right << setw(14)
<< fixed << s << " items"
<< right << setw(10) << fixed << "$ "
<< tax + r << endl;
}
int main(){
string menus;
int count = 0;
char choice;
string product;
double price;
const int Maxsize = 20;
int Order[Maxsize];
string products[Maxsize];
double money[Maxsize];
ifstream fileIn;
cout << "Welcome to Fredrick's Fast Foods
Reloaded!"<<endl;
cout << "Which menu would you like Normal or Kids? (N or K)
";
cin >> choice;
choice = toupper(choice);
if (choice == 'K'){
cout << "Here is the kids menu: " << endl;
fileIn.open("kids_menu.txt");
} else if(choice == 'N') {
cout << "Here is the normal menu: " << endl;
fileIn.open("normal_menu.txt");
} else{
cout << "Menu selection is invalid";
}
while(fileIn){
getline(fileIn, product, ',');
fileIn >> price;
products[count] = product;
money[count] = price;
cout << fixed << setprecision(2);
cout << product << " : $" << price <<
endl;
count++;
fileIn.get();
}
cout << "Please enter your order..." << endl;
pMenu(products, money, count, Order);
receipt (products,money,count,Order);
}
I am writing a program, I have everything setup, and I am needing help calling my...