我在做一个宏量营养素计算器。如果用户使错误计算器重新启动并返回到main(),则此计算器。不过,我相信我使用的main()在我的代码导致2所重新启动到主要功能
这里运行的显示是链接到我的代码:http://pastebin.com/FMqf2aRS
*******Welcome to the MACRONUTRIENT CALCULATOR********
Enter your calorie deficit: 30
Percentage of Protein: 30
Percent of Carbohydrates: 40
Percentage of Fats: 40
Total percentages surpassed 100! Please reenter percentages.
*******Welcome to the MACRONUTRIENT CALCULATOR********
Enter your calorie deficit: 2200
Percentage of Protein: 30
Percent of Carbohydrates: 30
Percentage of Fats: 40
You must eat 660.0 calories of protein which is equivalent to 165.0 grams of protein.
You must eat 880.0 calories of fat which is equivalent to 97.7777777778 grams of fat.
You must eat 660.0 calories of carbohydrates which is equivalent to 73.3333333333 grams of carbohydrates.
You must eat 9.0 calories of protein which is equivalent to 2.25 grams of protein.
You must eat 12.0 calories of fat which is equivalent to 1.33333333333 grams of fat.
You must eat 12.0 calories of carbohydrates which is equivalent to 1.33333333333 grams of carbohydrates.
有接近此不同的方式防止这种情况发生?
当然,不是要回'main',回到某个地方,只是做了计算。你可以通过从'main'中取出所有'输入'和计算等操作并将其放入一个名为'run'的函数来完成此操作。然后'main'在打印欢迎信息后调用'run()',如果你需要再次尝试,你可以再次调用'run'。 –