gpt4 book ai didi

c - 我的程序跳过获取输入数据?

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:19 25 4
gpt4 key购买 nike

<分区>

我编写了一个简单的程序来兑换货币并能够购买啤酒。

但程序中有一些东西,我不知道为什么,它会自动跳过第三个输入数据 -> 结束程序。

这里是我的代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int ex_rate_into_vnd = 20000; //! Exchange Rate
int beer = 7000; //! Local price of a beer
float in_c = 0; //! Input amount of money
float out_c = 2; //! Amount of currency to exchange !
float choice; //! Switch mode
char buy; //! Deal or not

//! Introduction
printf ("||---------------------------------------------------||\n");
printf ("|| Currency Exchange Machine beta ||\n");
printf ("||---------------------------------------------------||\n");

printf ("Please choose your option:\n");
printf("\t 1.Exchange VND to dollar\n");
printf("\t 2.Exchange Dollar to VND\n");

do
{
printf("Your choice: ",choice);
scanf("%f",&choice);
} while( choice != 1 && choice != 2);

printf ("Please enter amount of money:");
scanf("%f",&in_c);

if (choice == 1 )
{
out_c = in_c / ex_rate_into_vnd;
printf ("Your amount of money: %.2f",out_c);
}
else
{
out_c = in_c * ex_rate_into_vnd;
printf ("Your amount of money: %.0f",out_c);
}
//! End of Exchanging

printf ("\nWould you like to buy a beer (y/n) ?",buy);
scanf("%c", &buy);

if (buy == 'y')
{
if (out_c >= 7000)
{
out_c = out_c - 7000;
printf("Transactions success !\n");
printf("Your amount: %2.f",out_c);
}
}
printf ("\nWhy Stop ?");


return 0;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com