大佬教程收集整理的这篇文章主要介绍了计费系统总计的输出为 0,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream>
#include <String.h>
#include <iomanip>
#define MAX 8
using namespace std;
struct menuItemType{
String menuItem;
double menuprice;
};
menuItemType menuList[MAX];
voID getData();
voID showMenu();
int printcheck(voID);
//int b[8] = {0,0};
int main(){
cout << "Welcome to Mavel's Restaurant\n\n";
cout << "------------ Menu ------------ \n";
showMenu();
getData();
int choice;
char add;
do {
cout << "Enter choice: ";
cin >> choice;
switch (choicE){
case 1:
cout<< "You ordered Plain Egg.\n";
break;
case 2:
cout<< "You ordered BACon and Egg.\n";
break;
case 3:
cout<< "You ordered a muffin.\n";
break;
case 4:
cout<< "You ordered french Toast.\n";
break;
case 5:
cout<< "You ordered Fruit Basket.\n";
break;
case 6:
cout<< "You ordered Cereal.\n";
break;
case 7:
cout<< "You ordered Coffee.\n";
break;
case 8:
cout<< "You ordered Tea.\n";
break;
default:
cout<< "InvalID Choice.";
break;
}
cout<< "Would you like to order another item? [Y]es / [n]o : ";
cin >> add;
if (add == 'N'||add =='n'){
printcheck();
}
}
while (add == 'Y'|| add == 'y');
}
voID getData(){
menuList[0].menuItem = "Plain Egg";
menuList[0].menuprice = 140.50;
menuList[1].menuItem = "BACon and Egg";
menuList[1].menuprice = 245.00;
menuList[2].menuItem = "Muffin";
menuList[2].menuprice= 295.00;
menuList[3].menuItem = "french Toast";
menuList[3].menuprice = 495.00;
menuList[4].menuItem = "Fruit Basket";
menuList[4].menuprice = 555.00;
menuList[5].menuItem = "Cereal";
menuList[5].menuprice = 385.00;
menuList[6].menuItem = "Coffee";
menuList[6].menuprice = 415.00;
menuList[7].menuItem = "Tea";
menuList[7].menuprice = 333.00;
}
voID showMenu(){
cout << "[1] Plain Egg\t\t@R_674_11161@140.50\n";
cout << "[2] BACon and Egg\t@R_674_11161@245.00\n";
cout << "[3] Muffin\t\t@R_674_11161@295.00\n";
cout << "[4] french Toast\t@R_674_11161@495.00\n";
cout << "[5] Fruit Basket\t@R_674_11161@555.00\n";
cout << "[6] Cereal\t\t@R_674_11161@385.00\n";
cout << "[7] Coffee\t\t@R_674_11161@415.00\n";
cout << "[8] Tea\t\t\t@R_674_11161@333.00\n\n";
}
double @R_79_10586@l = 0;
int printcheck(){
getData();
double @R_79_10586@l = 0,tax,@R_79_10586@lbill;
for (int i = 0; i < 8; i++){
@R_79_10586@l += menuList[i].menuprice;
}
tax = @R_79_10586@l * 0.05;
@R_79_10586@lbill = @R_79_10586@l+tax;
cout << "----------------------------------------------\n";
cout << "Tax\t\t" << tax<< endl;
cout << "amount Due\t@R_674_11161@" << @R_79_10586@lbill << endl;
cout << "----------------------------------------------\n";
return @R_79_10586@l;
}
#include <iostream>
#include <String.h>
#include <iomanip>
#define MAX 8
using namespace std; // I would avoid using namespace std,explanation ahead
struct menuItemType
{
String menuItem;
double menuprice;
};
//menuItemType menulist[MAX]; //does not need to be global
void getData(menuItemType *menulist);
void showMenu();
int printcheck(double @R_79_10586@l); // pass the @R_79_10586@l to the printcheck() function
int main()
{
menuItemType menulist[MAX]; // go local when possible
cout << "Welcome to Mavel's Restaurant\n\n";
cout << "------------ Menu ------------ \n";
showMenu(); // here you could also pass menulist and print the menu using the data
//it would be easier to refactor if you add a menu item,try it
getData(menulist);
int choice;
char add;
double @R_79_10586@l = 0;
do
{
cout << "Enter choice: ";
cin >> choice;
// do the math in the cycle so you can keep track of the sum of SELEcted items
if(choice > 0 && choice <= MAX)
@R_79_10586@l += menulist[choice - 1].menuprice;
switch (choicE) // if you want to separate logic from UI,this could
// be a separate function,i.e. printChoice(choicE);
{
case 1:
cout << "You ordered Plain Egg.\n";
break;
case 2:
cout << "You ordered BACon and Egg.\n";
break;
case 3:
cout << "You ordered a muffin.\n";
break;
case 4:
cout << "You ordered French Toast.\n";
break;
case 5:
cout << "You ordered Fruit Basket.\n";
break;
case 6:
cout << "You ordered Cereal.\n";
break;
case 7:
cout << "You ordered Coffee.\n";
break;
case 8:
cout << "You ordered Tea.\n";
break;
default:
cout << "Invalid Choice.";
break;
}
cout << "Would you like to order another item? [Y]es / [n]o : ";
cin >> add;
if (add == 'N' || add == 'n') // this condition is also refactorable,you could
// simply move the print to after the loop ends
{
printcheck(@R_79_10586@l);
}
} while (add == 'Y' || add == 'y');
//printcheck(@R_79_10586@l); //here
}
void getData(menuItemType *menulist)
{
menulist[0].menuItem = "Plain Egg";
menulist[0].menuprice = 140.50;
menulist[1].menuItem = "BACon and Egg";
menulist[1].menuprice = 245.00;
menulist[2].menuItem = "Muffin";
menulist[2].menuprice = 295.00;
menulist[3].menuItem = "French Toast";
menulist[3].menuprice = 495.00;
menulist[4].menuItem = "Fruit Basket";
menulist[4].menuprice = 555.00;
menulist[5].menuItem = "Cereal";
menulist[5].menuprice = 385.00;
menulist[6].menuItem = "Coffee";
menulist[6].menuprice = 415.00;
menulist[7].menuItem = "Tea";
menulist[7].menuprice = 333.00;
}
void showMenu()
{
cout << "[1] Plain Egg\t\t@R_674_11161@140.50\n";
cout << "[2] BACon and Egg\t@R_674_11161@245.00\n";
cout << "[3] Muffin\t\t@R_674_11161@295.00\n";
cout << "[4] French Toast\t@R_674_11161@495.00\n";
cout << "[5] Fruit Basket\t@R_674_11161@555.00\n";
cout << "[6] Cereal\t\t@R_674_11161@385.00\n";
cout << "[7] Coffee\t\t@R_674_11161@415.00\n";
cout << "[8] Tea\t\t\t@R_674_11161@333.00\n\n";
}
// now can simply print the check
int printcheck(double @R_79_10586@l)
{
double tax = @R_79_10586@l * 0.05;
double @R_79_10586@lbill = @R_79_10586@l + tax;
cout << "----------------------------------------------\n";
cout << "Tax\t\t" << tax << endl;
cout << "amount Due\t@R_674_11161@" << @R_79_10586@lbill << endl;
cout << "----------------------------------------------\n";
return @R_79_10586@l; // you're not using this return value,you may aswell make the function return type void
}
@H_607_2@有关是否应使用 using namespace std;
的更多信息,请查看此链接:
@H_607_2@Why is "using namespace std;" considered bad practice?
@H_607_2@请注意,该代码仍有一些弱点,即缺乏输入验证,例如,如果在提示您输入 choice
时输入的不是数字,则说明有问题。如果您想了解更多相关信息,您可以在 SO 中找到许多主题,例如:
@H_607_2@Good input validation loop using cin - C++以上是大佬教程为你收集整理的计费系统总计的输出为 0全部内容,希望文章能够帮你解决计费系统总计的输出为 0所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。