gpt4 book ai didi

使用在 C 编程语言中不起作用的函数和参数转换货币

转载 作者:行者123 更新时间:2023-11-30 17:16:42 26 4
gpt4 key购买 nike

我正在尝试制作一个将欧元转换为美元以及将美元转换为欧元的程序但它无法正常工作,它只能从美元转换为欧元任何人都可以帮助我并告诉我错误在哪里吗?

#include <stdio.h>
#include <stdlib.h>
void convert(float euro);
void convert2(float dollar);

int main()
{
char what;
printf("if u want to convert from USD to Euro type U\n");
printf("if u want to convert from EURO to USD type E\n");
scanf("%c", &what);
if(what = 'U')
{

float howmany5;
printf("how many dollars\n");
scanf(" %f", &howmany5);
convert2(howmany5);
}
if(what = 'E')
{

printf(" how many euros\n");
float howmany;
scanf(" %f", &howmany);
convert(howmany);
}
return 0;
}
void convert(float euro)
{
float dollar = euro * 1.37;
printf("%0.2f euro - %.02f USD", euro, dollar);
return;
}
void convert2(float dollar)
{`enter code here`
float euro = dollar *0.8;
printf("%0.2f dollar - %.02f euro", dollar, euro);
return;`enter code here`
}

最佳答案

您正在执行赋值=而不是比较==,语句what = 'U'始终评估为true

if(what == 'U')
{

float howmany5;
printf("how many dollars\n");
scanf(" %f", &howmany5);
convert2(howmany5);
}
else if(what == 'E')
{

printf(" how many euros\n");
float howmany;
scanf(" %f", &howmany);
convert(howmany);
}

关于使用在 C 编程语言中不起作用的函数和参数转换货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29576755/

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