(最近的课设需要设计一个餐厅点菜的系统
在点菜的头文件和结算的头文件中我定义了一个全局变量extern int sum,并将其放在一个global的头文件里。
我打算是让这个变量可以储存点菜中的金额,并让其在结算中调用出来。)
麻烦大佬们帮我看下这个错误是怎么导致的
/*"global.h"的代码如下*/
extern int sum;
/*“点菜.h”如下*/
#include<stdlib.h>
#include<stdio.h>
#include"time.h"
#include"windows.h"
#include"string.h"
extern int sum;
void order()
{
int i, sel;
system("cls");
printf("\t\t\t******************************************************\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t***************欢迎来到城科餐厅点餐功能***************\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t******************************************************\n");
printf("\n\n\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t***************1 按菜名点餐 ****************\n");
printf("\t\t\t***************2 退出点餐 ****************\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t请你输入你的选择(1-2):");
scanf_s("%d", &sel);
while (sel < 1 || sel>2)
{
printf("\t\t\t 输入错误,请你重新输入你的选择(1-2):");
scanf_s("%d", &sel);
}
switch (sel)
{
case 1:
{
char order_cm[30];
int flag, x;
printf("\t\t\t请你输入你所要点餐的菜名:");
scanf_s("%s", &order_cm);
//把输入的菜名和所有菜品的菜名进行比对,是否相等,如果相等则输出
flag = 0; //0表没有找到
for (i = 0; i <= 39; i++)
{
if (order_cm == soft[i].cm)
{
flag = 1;//1表示找到了
sum += soft[i].price;
for (x = 1; x <= 103; x++)
printf("-");
printf("\n");
printf("|");
printf("%-9s", "菜名");
printf("|");
printf("%-9s", "菜品类型");
printf("|");
printf("%-9s", "价格");
printf("|");
printf("\n");
for (x = 1; x <= 103; x++)
printf("-");
printf("\n");
printf("|");
printf("%-9d", soft[i].cm);
printf("|");
printf("%-9d", soft[i].lx);
printf("|");
printf("%-9d", soft[i].price);
printf("|");
printf("\n");
for (x = 1; x <= 103; x++)
printf("-");
printf("\n");
break;
}
}
if (flag == 0)
printf("\t\t\t查无此菜品!!!\n");
system("pause");
order();//点餐以后继续点餐
}
break;
case 2:
break;
}
}
/*"结算.h"如下
#include<stdlib.h>
#include<stdio.h>
#include"time.h"
#include"windows.h"
#include"string.h"
extern int sum;
void billpay()
{
system("cls");
printf("\t\t\t******************************************************\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t***************欢迎来到城科餐厅结算功能***************\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t******************************************************\n");
printf("\n\n\n");
printf("\t\t\t******************************************************\n");
printf("\t\t\t********您需支付%d元**********\n",&sum);
system("pause");
}