这个计划的总体目的是为一家餐馆建立一个订餐服务。该程序的目的是从一个。txt文件中提取食品项目和价格,显示它们,让顾客挑选项目,然后在屏幕上打印账单。除了printCheck函数之外,这里的一切都可以正常工作。
null
null
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
};
menuItemType menuList[3];
void getData(menuItemType menuList[3]);
void showMenu(menuItemType menuList[3]);
void printCheck(double);
int main(){
getData(menuList);
showMenu(menuList);
printCheck;
return 0;
}
void getData(menuItemType menuList[3]) //This pulls the items and prices from the text file into the array
{
//declare variables
ifstream in_stream;
int i;
//open txt file
in_stream.open("menuitems.txt");
// loop to pull items from txt file into struct array
for (i = 0; i < 3 ; i++){
in_stream >> menuList[i].menuItem >> menuList[i].menuPrice;
}
}
void showMenu(menuItemType menuList[3])//shows the user the menu items and tells them how to select them
{
int selection;
double total;
int sentinel = 9;
//Welcome message and instructions for how to order
cout << "Welcome To The Restaurant" << endl;
cout << "Please select the items you would like: " << endl;
cout << "Press 9 to complete your order." << endl;
//displaying items from array onto screen
cout << menuList[0].menuItem << " $" << menuList[0].menuPrice << endl;
cout << menuList[1].menuItem << " $" << menuList[1].menuPrice << endl;
cout << menuList[2].menuItem << " $" << menuList[2].menuPrice << endl;
//while loop to allow user to select as many items as needed, and calculate total
while (selection != sentinel){
cin >> selection;
if (selection == 1){
total += 2.45;
cout << "You've selected Bacon" << endl;
}
else if (selection == 2){
total += .99;
cout << "You've selected a Muffin" << endl;
}
else if (selection == 3) {
total += .50;
cout << "You've selected coffee" << endl;
}
}
}
void printCheck(double total)
{
double after_tax;
const double tax = .05;
cout << "Total Bill: $" << total << endl;
after_tax = total + (total * tax);
cout << setprecision(2) << "Total Check After Tax: $" << after_tax << endl;
}
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
};
menuItemType menuList[3];
void getData(menuItemType menuList[3]);
void showMenu(menuItemType menuList[3]);
void printCheck(double);
int main(){
getData(menuList);
double total = showMenu(menuList);
printCheck(total);
return 0;
}
void getData(menuItemType menuList[3]) //This pulls the items and prices from the text file into the array
{
//declare variables
ifstream in_stream;
int i;
//open txt file
in_stream.open("menuitems.txt");
// loop to pull items from txt file into struct array
for (i = 0; i < 3 ; i++){
in_stream >> menuList[i].menuItem >> menuList[i].menuPrice;
}
}
double showMenu(menuItemType menuList[3])//shows the user the menu items and tells them how to select them
{
int selection;
double total = 0.0;
int sentinel = 9;
//Welcome message and instructions for how to order
cout << "Welcome To The Restaurant" << endl;
cout << "Please select the items you would like: " << endl;
cout << "Press 9 to complete your order." << endl;
//displaying items from array onto screen
cout << menuList[0].menuItem << " $" << menuList[0].menuPrice << endl;
cout << menuList[1].menuItem << " $" << menuList[1].menuPrice << endl;
cout << menuList[2].menuItem << " $" << menuList[2].menuPrice << endl;
//while loop to allow user to select as many items as needed, and calculate total
do {
cin >> selection;
if (selection == 1){
total += 2.45;
cout << "You've selected Bacon" << endl;
}
else if (selection == 2){
total += .99;
cout << "You've selected a Muffin" << endl;
}
else if (selection == 3) {
total += .50;
cout << "You've selected coffee" << endl;
}
} while (selection != sentinel)
return total;
}
void printCheck(double total)
{
double after_tax;
const double tax = .05;
cout << "Total Bill: $" << total << endl;
after_tax = total + (total * tax);
cout << setprecision(2) << "Total Check After Tax: $" << after_tax << endl;
}