【发布时间】:2016-02-21 12:36:13
【问题描述】:
我正在尝试像这样使用定义
`printf ("1st Account:");
scanf("%i",&AN1);
printf ("Value of 1st Account:");
scanf("%f",&VAN1);
printf ("2nd Account:");
scanf("%i",&AN2);
printf ("Value of 2nd Account:");
scanf("%f",&VAN2);
system("pause");
system("cls");
if (AN1==101)
#define CAN1 "Cash"
else if (AN1==102)
#define CAN1 "Accounts Receivable"
else if (AN1==104)
#define CAN1 "Notes Receivable"`
等等
显然,它不起作用,因为 define 是针对整个程序的,并且不是仅在 if 语句中读取的。
有人知道如何让它工作吗? 我需要稍后显示它,就像这样
`printf ("Your 1st account name is: %s with the value of %.2f.\n",CAN1,VAN1);
printf ("Your 2nd account name is: %s with the value of %.2f.\n",CAN2,VAN2);`
【问题讨论】: