我需要帮助重复这个程序......(C程序) [英] I need help repeating this program... ( C program )

查看:61
本文介绍了我需要帮助重复这个程序......(C程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们。我欢迎来到CodeProject网站哈哈!



(在这里编程的新手,但不知何故可以理解)



所以让我们切入追逐...

我用C语言编写了一个餐厅订购程序,一切都运行良好'直到总量和东西......



但我一直在寻找重复整个计划的方法,



到目前为止,我试过这样的样本输出如下:



你的总数是:______



你想重复吗?:



每次按Y,程序都会立即结束N,而不是显示



结束





我该怎么办? :/



TIA



-有问候。



我的尝试:



 #include< stdio.h> 
#include< stdlib.h>
#include< ctype.h>
#define p printf
#define s scanf

void Order();
void早餐();
无效午餐();
void总计(浮动总计);
void Repeat();

main()
{
Order();
}

void订单()
{
char choice;

p(欢迎来到JABEE iTECH!\ n);
p(订购哪种食品?\ n);
p(A ---- BREAKFAST \ n);
p(B ---- LUNCH \ n);
p(选择在这里:);

choice = toupper(getchar());
getchar();
开关(选择)
{
案例'A':
早餐();
休息;
案'B':
午餐();
休息;
}
}

void早餐()
{
char choicee;
浮动价格,总计;
int qty;

p(欢迎来到早餐区!\ n);
p(A ---- EGGS \ n);
p(B ---- BACON \ n);
p(选择在这里:);

choicee = toupper(getchar());
getchar();
开关(选择)
{
案例'A':
p(你选择EGGS \ n);
p(HOW MANY SERVINGS?:);
s(%d,& qty);

price = 19.99;
总=价格*数量;

总计(总计);
休息;

案例'B':
p(你选择BACON \ n);
p(HOW MANY SERVINGS?:);
s(%d,& qty);

price = 29.99;
总=价格*数量;

总计(总计);
休息;
}
}

无效午餐()
{
char choiceee;
浮动价格,总计;
int qty;

p(欢迎来到午餐区!\ n);
p(A ---- FISH \ n);
p(B ---- CHICKEN \ n);
p(选择在这里:);

choiceee = toupper(getchar());
getchar();
开关(选择)
{
案例'A':
p(你选择FISH \ n);
p(HOW MANY SERVINGS?:);
s(%d,& qty);

price = 39.99;
总=价格*数量;

总计(总计);
休息;

案例'B':
p(你选择鸡肉);
p(HOW MANY SERVINGS?:);
s(%d,& qty);

price = 49.99;
总=价格*数量;

总计(总计);
休息;
}
}

void总计(浮动全部)
{
p(你的全部是:%。2f \ n,总计);

Repeat();
}

void重复()
{
char choiceeee;

p(你想重复吗?:);
s(%c,& choiceeee);
开关(choiceeee)
{
案例'Y':
main();
休息;
案例'N':
p(END);
休息;
}
}

解决方案

更改 main 功能:

 main()
{
Order();
}

在这里包含一个循环,询问用户是否要再次执行此操作,如果没有,则退出循环。提示:一个做...而循环可能就是你想要的。在循环内部,你执行 Order ,然后问他是否要继续。

然后删除重复 function。


Hey guys. I welcome myself to CodeProject website HA HA!

(newb to programming here, but somehow can understand)

So let's cut to the chase...
I made a restaurant ordering program coded in C language, and everything works fine up 'till the total amount and stuff...

But I've been looking for ways to repeat this whole program,

and as of now, I tried like this sample output as follows:

Your Total is: ______

Do you want to repeat?:

And everytime I press Y, the program ends instantaneously while N, not showing

End


What should I do? :/

T.I.A.

-with regards.

What I have tried:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define p printf
#define s scanf

void Order();
void Breakfast();
void Lunch();
void Total(float totall);
void Repeat();

main()
{
	Order();
}

void Order()
{
	char choice;
	
	p("WELCOME TO JABEE iTECH!\n");
	p("WHICH FOOD COURSE TO ORDER?\n");
	p("A ---- BREAKFAST\n");
	p("B ---- LUNCH\n");
	p("CHOICE HERE: ");
	
	choice = toupper(getchar());
	getchar();
	switch(choice)
	{
		case 'A':
			Breakfast();
			break;
		case 'B':
			Lunch();
			break;
	}
}

void Breakfast()
{
	char choicee;
	float price, total;
	int qty;
	
	p("WELCOME TO BREAKFAST SECTION!\n");
	p("A ---- EGGS\n");
	p("B ---- BACON\n");
	p("CHOICE HERE: ");
	
	choicee = toupper(getchar());
	getchar();
	switch(choicee)
	{
		case 'A':
			p("YOU CHOSE EGGS\n");
			p("HOW MANY SERVINGS?: ");
			s("%d", &qty);
			
			price = 19.99;
			total = price * qty;
			
			Total(total);
			break;
			
		case 'B':
			p("YOU CHOSE BACON\n");
			p("HOW MANY SERVINGS?: ");
			s("%d", &qty);
			
			price = 29.99;
			total = price * qty;
			
			Total(total);
			break;
	}
}

void Lunch()
{
	char choiceee;
	float price, total;
	int qty;
	
	p("WELCOME TO LUNCH SECTION!\n");
	p("A ---- FISH\n");
	p("B ---- CHICKEN\n");
	p("CHOICE HERE: ");
	
	choiceee = toupper(getchar());
	getchar();
	switch(choiceee)
	{
		case 'A':
			p("YOU CHOSE FISH\n");
			p("HOW MANY SERVINGS?: ");
			s("%d", &qty);
			
			price = 39.99;
			total = price * qty;
			
			Total(total);
			break;
			
		case 'B':
			p("YOU CHOSE CHICKEN\n");
			p("HOW MANY SERVINGS?: ");
			s("%d", &qty);
			
			price = 49.99;
			total = price * qty;
			
			Total(total);
			break;
	}
}

void Total(float totall)
{
	p("YOUR TOTAL IS: %.2f\n", totall);
	
	Repeat();
}

void Repeat()
{
	char choiceeee;
	
	p("DO YOU WANT TO REPEAT?: ");
	s("%c", &choiceeee);
	switch(choiceeee)
	{
		case 'Y':
			main();
			break;
		case 'N':
			p("END");
			break;
	}
}

解决方案

Change your main function:

main()
    {
    Order();
    }

Include a loop here, which asks the user if he wants to do it again, and if not, exits the loop. Hint: a do...while loop would probably be what you wanted. Inside the loop, you do Order once, and then ask him if he wants to continue.
Then delete the Repeat function.


这篇关于我需要帮助重复这个程序......(C程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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