【发布时间】:2015-06-17 01:50:58
【问题描述】:
我正在尝试制作一个将欧元转换为美元和美元转换为欧元的程序 bur它不能正常工作它只能从美元转换为欧元 谁能帮助我并告诉我错误在哪里?
#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`
}
【问题讨论】:
-
好的,我修好了,我只需要添加另一个 = 符号
-
避免这个错误的一个技巧是使用
'U' == what而不是what == 'U',所以如果你错过了=,你会得到一个编译器错误。 -
哦,谢谢你,一些愚蠢的错误会导致完美:)
-
@user4098326 agrees Yoda