【问题标题】:converting currency using functions and arguments not working in c programming language使用不适用于 c 编程语言的函数和参数转换货币
【发布时间】: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

标签: c function arguments


【解决方案1】:

你正在做赋值=而不是比较==,语句what = 'U'总是评估为真

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);
}

【讨论】:

    猜你喜欢
    • 2019-10-24
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多