【发布时间】:2015-04-12 16:23:59
【问题描述】:
这个程序可以按照我的意愿运行,但只有一个错误。它不会从欧元转换成美元,它只是给我
0.0 欧元 = 0.0 美元;
你们能帮帮我吗?
#include <stdio.h>
#include <stdlib.h>
void dollar(float dollar);
int main()
{
char what;
int howmany;
int i;
float dollar2;
float euro2;
printf("enter how many times do you want to convert\n");
scanf(" %d", &howmany);
printf("enter U if you want to convert from USD to Euro\n");
printf("enter E if you want to convert from Euro to USD\n");
for(i=0; i<=howmany-1; i++)
{
scanf(" %c", &what);
if(what == 'E')
{
printf(" Enter how many euros do you want to convert\n");
scanf(" %f", &euro2);
euro(euro2);
}
if(what == 'U' ){
printf(" Enter how many dollars do you want to convert\n");
scanf(" %f", &dollar2);
dollar(dollar2);
}
}
return 0;
}
void dollar(float dollar)
{
float euro = 0.94 * dollar;
printf("%0.2f dollar = %0.2f euro\n", dollar, euro);
return;
}
void euro(float euro)
{
float dollar = 1.37 * euro;
printf("%0.2f EURO = %0.2f DOLLAR\n", euro, dollar);
return;
}
【问题讨论】:
-
我先输入 4 然后它要求输入货币所以我输入 E 就是这样
-
是的,它适用于美元,但不适用于欧元!
-
声明
euro函数的原型可能是个好主意。 -
我工作不好最后忘记添加欧元函数的原型
-
您没有检查
scanf()返回值,它可能由于语言环境或其他问题而无法scanf()输入,但您不知道,因为您忽略了返回价值。