C 伊扎\n”); 价格=105.00; 打破 案例S: printf(“您选择了三明治”\n); 价格=75.50; 打破 违约: fprintf(标准“无效食品!\n”); 中止(); } printf(“输入数量:”); 整数; 如果(扫描频率(“%d”,&数量)!=1){ perror(“扫描错误”); 中止(); } 退货(浮动)价格*(浮动)数量; }

C 伊扎\n”); 价格=105.00; 打破 案例S: printf(“您选择了三明治”\n); 价格=75.50; 打破 违约: fprintf(标准“无效食品!\n”); 中止(); } printf(“输入数量:”); 整数; 如果(扫描频率(“%d”,&数量)!=1){ perror(“扫描错误”); 中止(); } 退货(浮动)价格*(浮动)数量; },c,C,当您在用户输入后调用菜单时为[1]是。使用menu()函数show menu和after menu,您应该显示call food()函数 这是你想要的 #include<stdio.h> #include<stdlib.h> #include<conio.h> void menu(); void foods(); void main(); char food; int quantity; float price; float total; float gra

当您在用户输入后调用菜单时为[1]是。使用menu()函数show menu和after menu,您应该显示call food()函数

这是你想要的

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

void menu();
void foods();
void main();
char food;
int quantity;
float price;
float total;
float grandtotal;
int choice;

void main()
{


    clrscr();
    do {
        menu();
        foods();

        printf("\n Do you want to order more? [1] Yes [2] No:");
        scanf("%d", &choice);
        getchar();  // <== remove newline
        grandtotal = grandtotal + total;
    } while (choice == 1);

        printf("\n Total Price is: %0.2f", grandtotal);
    getch();
}

void menu() {

    food = ' ';
    quantity = 0;
    price = 0;
    total = 0;
    choice = 0;
    printf("Please select food from the following:\n");
    printf(" B = Burger, F = French Fries, P = Pizza, S = Sandwiches \n");

    printf("Enter food:");
    scanf("%c", &food);
}

void foods() {
    switch (food)
    {
    case 'B':
        printf("You selected Burger!\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 95.50;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);
        //getchar();  // <== remove newline

        total = price*quantity;
        break;

        //if (choice == 1) {

        //  menu();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    case 'F':
        printf("You selected French Fries!\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 47.75;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);

        total = price*quantity;
        break;
        //if (choice == 1) {
        //  menu();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    case 'P':
        printf("You selected French Pizza!\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 105.00;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);

        total = price*quantity;
        break;
        //if (choice == 1) {
        //  menu();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    case 'S':
        printf("You selected Sandwiches\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 75.50;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);

        total = price*quantity;
        break;
        //if (choice == 1) {
        //  main();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    default:
        printf("INVALID FOOD!");
        break;

    }
}
#包括
#包括
#包括
无效菜单();
使食物无效();
void main();
炭化食品;
整数;
浮动价格;
浮动总额;
浮动总额;
智力选择;
void main()
{
clrsc();
做{
菜单();
食品();
printf(“\n您想订购更多吗?[1]是[2]否:”);
scanf(“%d”,选择(&C);

GETBAL()://首先:您的代码是正确的。TurBoc是过时的、非标准的一致性的C实现。考虑使用更好的东西(例如,在Windows上)。请注意,C和C++是不同的编程语言。<代码> \n>代码>应该是<代码> Prtff<代码>格式,因为 StdOut可以是行缓冲的。我真的不喜欢你的<代码>菜单< /Cuff>函数调用<代码>主< /代码>。没有什么对不起,你在正确的地方。URBO C/C++编译器非常重要,尤其是如果你依赖于与编译器相关的旧文档。Borland Turbo C+C++编译器的名字大约是1990(几年后有几个版本更新,但是在当前C标准之前和在任何有意义的C++标准之前的几十年)。。除非您的硬件是实现定义的嵌入式系统,
void main()
对于符合要求的编译器来说不是一个有效的程序启动。在查看了您的程序后,我决定向您展示一种更简洁的方法。这绝对不是防弹的或漂亮的代码,但希望您能看到它更易于维护。谢谢您的建议,先生,我采纳了您的建议,但在我选择了1之后,它仍然很接近如果我想订购更多,请点击我。对,scanf中的
%c
返回一个换行符。先生,这个修订版真的很有效!我会在评论中写下你的所有建议!剩下的唯一问题是,当我决定不再订购时,它没有显示正确的总计,它只显示上一个订单的总计。好的,现在再次检查@ASCIIThank“太多了!@amin
...
if(choice == 1){
   menu();
   break;
} ...
...
...
if(choice == 1){
   menu();
   foods();
   break;
} ...
...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

char menu(void);
float foods(char food);

void main()
{
    clrscr();

    float grandtotal = 0;

    int choice = 0;
    do {
        // print menu and choose the food
        char food = menu();
        // choose food quantity and get it's price
        float total = foods(food);

        // print the total price
        grandtotal = grandtotal + total;
        printf("\n Total Price is: %0.2f", grandtotal);

        // do you want to continue?
        printf("\n Do you want to order more? [1] Yes [2] No:");
        if (scanf("%d", &choice) != 1) {
            perror("scanf error");
            abort();
        }

        // continue until choice is equal to 1
    } while (choice != 1);
}

char menu(void)
{
    char food;
    printf("Please select food from the following:\n");
    printf(" B = Burger, F = French Fries, P = Pizza, S = Sandwiches \n");
    printf("Enter food:");
    if (scanf(" %c", &food) != 1) {
        perror("scanf error");
        abort();
    }
    return food;
}

float foods(char food){
    float price = 0;
    switch (food) {
    case 'B':
        printf("You selected Burger!\n");
        price = 95.50;
        break;
    case 'F':
        printf("You selected French Fries!\n");
        price = 47.75;
        break;
    case 'P':
        printf("You selected French Pizza!\n");
        price = 105.00;
        break;
    case 'S':
        printf("You selected Sandwiches\n");
        price = 75.50;
        break;
    default:
        fprintf(stderr, "INVALID FOOD!\n");
        abort();
    }

    printf("Enter quantity:");
    int quantity;
    if (scanf("%d", &quantity) != 1) {
        perror("scanf error");
        abort();
    }

    return (float)price * (float)quantity;
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

void menu();
void foods();
void main();
char food;
int quantity;
float price;
float total;
float grandtotal;
int choice;

void main()
{


    clrscr();
    do {
        menu();
        foods();

        printf("\n Do you want to order more? [1] Yes [2] No:");
        scanf("%d", &choice);
        getchar();  // <== remove newline
        grandtotal = grandtotal + total;
    } while (choice == 1);

        printf("\n Total Price is: %0.2f", grandtotal);
    getch();
}

void menu() {

    food = ' ';
    quantity = 0;
    price = 0;
    total = 0;
    choice = 0;
    printf("Please select food from the following:\n");
    printf(" B = Burger, F = French Fries, P = Pizza, S = Sandwiches \n");

    printf("Enter food:");
    scanf("%c", &food);
}

void foods() {
    switch (food)
    {
    case 'B':
        printf("You selected Burger!\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 95.50;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);
        //getchar();  // <== remove newline

        total = price*quantity;
        break;

        //if (choice == 1) {

        //  menu();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    case 'F':
        printf("You selected French Fries!\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 47.75;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);

        total = price*quantity;
        break;
        //if (choice == 1) {
        //  menu();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    case 'P':
        printf("You selected French Pizza!\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 105.00;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);

        total = price*quantity;
        break;
        //if (choice == 1) {
        //  menu();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    case 'S':
        printf("You selected Sandwiches\n");
        printf("Enter quantity:");
        scanf("%d", &quantity);
        price = 75.50;

        //printf("\n Do you want to order more? [1] Yes [2] No:");
        //scanf("%d", &choice);

        total = price*quantity;
        break;
        //if (choice == 1) {
        //  main();
        //  break;
        //}
        //else if (choice == 2) {
        //  grandtotal = grandtotal + total;
        //  printf("\n Total Price is: %0.2f", grandtotal);
        //  break;
        //}

    default:
        printf("INVALID FOOD!");
        break;

    }
}