如何在最后一个if语句中重复我的代码 [英] How Can I Repeat My Code in the last if statement

查看:61
本文介绍了如何在最后一个if语句中重复我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>

int  printMenu()

{


int response;

fprintf(stdout,"\n\n\n               *********************************************\n");
fprintf(stdout,"			        FOOD COURT		  \n ");
fprintf(stdout,"              *********************************************\n\n\n");
fprintf(stdout,"                         Welcome to the Food court   \n\n");
fprintf(stdout,"    Make your selection from the given MENU below:\n\n\n");

fprintf(stdout,"	 1. Thums up			            60.00   \n");
fprintf(stdout,"	 2. Sprite			            60.00   \n");
fprintf(stdout,"	 3. Coke			            60.00   \n");
fprintf(stdout,"	 4. Regular Cheeseburger		    45.00   \n");
fprintf(stdout,"	 5. Fish Sandwich			    70.00   \n");
fprintf(stdout,"	 6. French fries			    55.00   \n");
fprintf(stdout,"	 7. Candies         			    40.00   \n");
fprintf(stdout,"	 8. Dairy milk		                    50.00   \n");
fprintf(stdout,"	 9. Milky bar			            45.00   \n");
fprintf(stdout,"\n\n              *********************************************\n\n");
fprintf(stdout,"Enter the choice from FOOD COURT Menu \n\n");
fscanf(stdin, "%d", &response);
return response;
}

int main()

{
  int s,r;
  float p, x;
  int response;
  int sub;

  response = printMenu();
  printf("How many orders of item number %d would you like?\n", response);
  scanf("%d", &s);

  switch (response){
   case 1:
   printf("You have ordered %d order(s) of the Thums up\n");
   p=s * 60.00;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 2:
   printf("You have ordered %d order(s) of the Sprite \n", s);
   p=s*60.00;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 3:
   printf("You have ordered %d order(s) of the Coke\n", s);
   p=s*60.000;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 4:
   printf("You have ordered %d order(s) of the Regular Cheeseburger\n", s);
   p=s*45;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 5:
   printf("You have ordered %d order(s) of the Fish Sandwich\n", s);
   p=s*70;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 6:
   printf("You have ordered %d order(s) of the French fries \n", s);
   p=s*55;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 7:
   printf("You have ordered %d order(s) Candies \n", s);
   p=s*40;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 8:
   printf("You have ordered %d order(s) Dairy Milk \n", s);
   p=s*50;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;

   case 9:
   printf("You have ordered %d order(s) Milky bar\n", s);
   p=s*45;
   printf("Net Ordered Amount:  %.2f\n\n", p);
   break;


   default:
   printf(" \n\nError:  This is not on the menu. \n");
   break;
   }

printf("Do you have anything else\n1.Yes\n2.No\n\n");
scanf("%d",&r);
if(r==1)
{

}
else
printf("your Total Amount:%.2f\n\n",p);
x=p*1.13;
printf("Please pay  %.2f\n\n",x);
printf("Service Tax & VAT TAX of 1.13 was included.\n\n\n\n");
printf("                      Thank you for eating at FOOD COURT\n\n");
fprintf(stdout,"               *********************************************\n");
fprintf(stdout,"			        VISIT AGAIN		  \n ");
fprintf(stdout,"              *********************************************\n\n");
}

推荐答案

循环怎么样,比如do / while循环。



How about a loop, like a do/while loop.

do {

     // do some stuff, set r to some value

   } while (r == 1);


Quote:

如何在最后重复我的代码if语句

How Can I Repeat My Code in the last if statement

无法在复制代码内部的位置复制一段代码,因为每次复制代码时,都会创建一个新的位置,您必须复制代码,它永远不会结束。 />


您必须找到一种方法来执行您的代码多次而不重复它。

It is impossible to copy a piece of code at a place which is inside the code copied because every times you copy the code, it create a new place where you must copy the code, it never end.

You have to find a way to execute your code more than once without duplicating it.


这篇关于如何在最后一个if语句中重复我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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