【发布时间】:2020-05-29 07:45:29
【问题描述】:
在用户从菜单中选择一个选项后,我正试图让我的程序从头开始。
当用户选择 1 然后输入捐赠金额时,我希望程序重新启动并显示菜单 What would you like to do? 而不仅仅是重新启动 if 语句。
我应该在 if 语句中添加一个 for 循环来完成这个吗?感谢您的帮助。
printf("What would you like to do?\n");
printf(" 1 - Donate\n");
printf(" 2 - Invest\n");
printf(" 3 - Print balance\n");
printf(" 4 - Exit\n");
printf("\n");
//scans menu choice
scanf("%d", &menu_option);
if(menu_option==1)
{
printf("How much do you want to donate?\n");
scanf("%lf", &donation);
donations_made++;
current_Balance = initial_Balance + donation;
}
【问题讨论】:
-
将所有内容放入
for(;;) {并执行break;以在除案例1 之外的所有情况下退出循环 -
把它放在一个循环中。
标签: c for-loop if-statement