假设储蓄和支出是已给定值的double类型变量。编写一个 if-else 语句,输出单词 Solvent,将 Savings 的值减去费用的值,并将费用的值设置为 0(前提是节省的费用大于费用)。但是,如果储蓄小于支出,则 if-else 语句仅输出单词破产,并且不会更改任何变量的值。
具体问题:为什么我的程序在我输入储蓄值后立即跳过?我该如何补救?
#include <stdio.h>
void solvent();
int main(void)
{
double savings, expenses;
printf("\nEnter a number for savings: ");
scanf("%2lf", &savings);
printf("Enter a number for expenses: ");
scanf("%2lf", &expenses);
if(savings > expenses)
solvent();
else
printf("Bankrupt!");
system("pause");
return 0;
}
void solvent(double savings, double expenses)
{
printf("Solvent!");
savings -= expenses;
expenses = 0;
}
最佳答案
好吧,出于我不太明白的原因,将 %2lf
设为 %lf
足以解决此问题。感谢风向标。
关于c - 为什么我的程序不允许我进行第二次输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49182537/