我对 C 相当陌生,我正在尝试使用 int 数组作为这样的开关的选项编号
void totalEntered(float * total, float * inputFigure)
{
*total = *total + *inputFigure;
}
int main()
{
float amountEntered = 0.00;
float tot = 0.00;
int option_numbers[3] = {1,2,3,4};
float a_food = 0.00;
float a_tab = 0.00;
float a_trav = 0.00;
float a_bill = 0.00;
totalEntered(&tot, &amountEntered);
printf("Please enter option number from below \n1.food\n2.tabacco\n3.travel\n4.bills\n");
scanf("%i", option_numbers);
switch(option_numbers)
{
case 1:
printf("Please Enter an amount: ");
scanf("%f", amountEntered);
a_food = a_food + amountEntered;
totalEntered(&tot, &amountEntered);
printf("You have spent %f on food", a_food);
break;
case 2: /*ignore below haven't finish that*/
a_tab = a_tab + amountEntered;
printf("You have spent %.2f on tabacco", a_tab);
break;
case 3:
a_trav = a_trav + amountEntered;
printf("You have spent %.2f on travel", a_trav);
break;
case 4:
a_bill = a_bill + amountEntered;
printf("You have spent %.2f on travel", a_bill);
break;
default:
printf("You have not input a category!");
break;
}
return 0;
}
任何人都可以建议如何解决这个问题......我有点卡住了!:DI 试图让用户选择一个 == 的数字,如果用户想在食物下输入一个金额,他/她必须选择选项 1,然后选择一个金额。希望这比以前更有意义!谢谢