【发布时间】:2018-11-30 02:02:20
【问题描述】:
在初学者的 C 课程中创建银行家程序。我的所有代码都成功运行(在测试了所有案例之后),除了在循环的一部分中强制返回负数。当值通过复制返回到主程序时,它会改变余额。
函数返回
else { //If the amount to be withdrawn from the account is greater than the existing amount
printf("Error. Withdrawal must be less than account balance.\n"); //Output error message
return -1; //Return a negative one to the main program
}
在 main 中复制返回
案例3://提现
printf("You are about to withdraw cash from an account.\n \n");
withdrawnAmount = withdrawal(balance); //Calling function to withdraw money from existing account
balance -= withdrawnAmount;
printf("Your new account balance is $%d\n\n", balance);
break;
【问题讨论】:
-
强烈建议不要使用图片。请发布实际代码。
-
抱歉,我试图以正确的格式显示实际代码。
-
请提供minimal reproducible example 并更好地解释问题。
标签: c function debugging return