如何根据用户的选择进行用户给出的不同输入的格式 [英] How can I do the grandtotal of different input given by user depending upon their choice

查看:101
本文介绍了如何根据用户的选择进行用户给出的不同输入的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作账单系统项目。

用户将输入产品编号和数量。程序将一直运行直到用户输入'y'。当用户按下'n'程序时将显示格兰特。

我已经创建了一些程序结构,但我仍然坚持使用grandtotal。我很担心如何处理不同产品和数量的格式。

请我请求你使用循环,做一会儿等,因为我是11级的学生。我只学过基础知识。



我有什么试过:



i am making a bill system project.
The user will enter product number and quantity.The program will run till the user enter 'y'.When the user will press 'n' the program will show the grandtotal.
I have created some structure of program but i am stuck with the grandtotal.I am relly confused how can i do the grandtotal of different product and quantity.
Please i request you to use loop,do while,etc as i am student of class 11.I have learned only basics.

What I have tried:

#include<iostream.h>                   7
#include<conio.h>
int calculate(int quantity, int price)
{
    // this is an oversimplification of a function

    int tot = quantity * price;
    return tot;     }
void main()
{
clrscr();
start:
cout<<"--------------------------------HOTEL RED CHILLIES------------------------------" ;
cout<<"                             M.G.ROAD RAIPUR - 492001";
cout<<"\n\t\t\t\tPHONE: 0771-4024196";
cout<<"\n--------------------------------------------------------------------------------";

cout<<"*CATEGORIES*\t\tPrice\t\t *CATEGORIES*\t\tPrice"  ;

cout<<"\n\nChinese Noodles\t\t\t Pizza";
cout<<"\n\n1.Veg Chowmein\t\t 100 \t\t 7.Red Green Pizza\t 160";
cout<<"\n2.Chili Garlic Noodles\t 100\t\t 8.Deluxe Margherita\t 180";
cout<<"\n3.American Chop Suey\t 110\t\t 9.Tomato Deluxe\t 180";

cout<<"\n------------------------------\t\t -----------------------------";

cout<<"\n\nPasta\t\t\t\t\t Soup";
cout<<"\n\n4.Pasta Red Sauce\t 160\t\t 10.Hot and Sour\t 70";
cout<<"\n5.Pasta Mexican\t\t 160\t\t 11.Tomato Soup\t\t 70";
cout<<"\n6.Pasta White Sauce\t 170\t\t 12.Manchow Soup\t 70";

cout<<"\n-------------------------------\t\t -----------------------------";
int num,qt,total;
char pro;
int grandtotal;
grandtotal=0;
do
{cout<<"\nEnter the product number(1-12)- ";
cin>>num;
switch(num)
{
case 1: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=100*qt;

	break;
case 2: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=100*qt;

	break;
case 3: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=110*qt;

	break;
case 4: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=160*qt;

	break;
case 5: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=160*qt;

	break;
case 6: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=170*qt;

	break;
case 7: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=160*qt;

	break;
case 8: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=180*qt;

	break;
case 9: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=180*qt;

	break;
case 10: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=70*qt;

	break;
case 11: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=70*qt;

	break;
case 12: cout<<"\nEnter the quantity- ";
	cin>>qt;
	total=70*qt;

	break;
}


cout<<"\nDo you want to order any other product(y/n) ";
cin>>pro;

if(pro=='y')
{
clrscr();
goto start;




}
grandtotal=grandtotal+total;

}
while(pro=='y');




if(pro=='n')
cout<<"total is"<<grandtotal;










getch();
}

推荐答案

您已在用户将在他们想要的时间输入产品和数量,当他们不希望程序显示总账单时 [ ^ ],我告诉你如何得到答案。



请不要重新发布同样的问题。
You already posted this question at The user will enter product and quantity while they want and when they do not want the program should show a total bill[^], and I showed you how to get the answer.

Please do not repost the same question.


这篇关于如何根据用户的选择进行用户给出的不同输入的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆