在我的代码的这一部分中,我提示用户开始使用银行余额(这样可以正常工作),然后我提示用户输入一个赌注值(也可以正常工作),但是问题是在最终功能,我试图确保他们输入的赌注的价值小于或等于他们银行的钱。然而,我继续得到do while循环重复,除非我输入一个负数,所以只是为了确保正确传递值我打印出两个语句只是为了看到这些值,你知道什么 bank_balance < / em>和 wager 打印为0.这是为什么?很抱歉,如果这是一个简单的问题,这是我的第一堂课程。
//The function for asking the player how much money they would like to start with.
double get_bank_balance (void)
{
double bank_balance = 0;
printf("Enter the amount of money you would like to start with (In USD): ");
scanf("%lf", &bank_balance);
printf("%s%.2lf%s", "Your current bank balance is: $", bank_balance, ".\n");
return bank_balance;
}
//This function prompts the user for the amount of currency they would like to wager
double get_wager_amount (void)
{
double wager = 0;
printf("Enter how much you would like to wager: ");
scanf ("%lf", &wager);
printf("%s%.2lf%s", "You will now wager $", wager, ".\n");
return wager;
}
//This function checks to see if the wager amount inputed by the user is an amount that is not over the amount in the users bank
int check_wager_amount (double wager, double bank_balance)
{
int check = 0;
printf("%s%.3lf%s", "Your banks at ", bank_balance, ".\n"); //returns 0
printf("%s%.3lf%s", "Your wagers at ", wager, ".\n"); //returns 0
do
{
if (wager <= bank_balance)
{
check = 1;
}
if (wager > bank_balance)
{
check = 0;
}
}while (check == 0);
}