#include <stdio.h>
int main() {
//US CONVERSION RATES
float const usToGBP = .78;
float const usToAUD = 1.40;
float const usToBit = .00027;
float const usToEur = .88;
float const usToCAD = 1.33;
//GBP CONVERSION RATES
float const gbpToUS = 1.29;
float const audToUS = .72;
float const bitToUS = 3696.11;
float const euroToUS = 1.14;
float const cadToUS = .75;
//////////////////////////
float amount;
printf("How much currency do you have? ");
scanf("%f", amount);
//NOTHING BELOW PRINTS
printf("%f", amount);
printf("HEYYY");
printf("|| US || GBP || AUD || BIT || EUR || CAD
||");
我是C语言的新手,所以我仍在学习基本输入和输出的语法。目前,我正在尝试编写一个简单的程序来转换货币。我使用scanf
来收取一定金额,但是,当我尝试在此之后打印任何东西(例如表格或金额)时,则什么都没显示?有人可以解释为什么会这样吗?
答案 0 :(得分:2)
应该是
scanf("%f", &amount);
答案 1 :(得分:1)
输入时您未使用&符号
#include <stdio.h>
int main() {
//US CONVERSION RATES
float const usToGBP = .78;
float const usToAUD = 1.40;
float const usToBit = .00027;
float const usToEur = .88;
float const usToCAD = 1.33;
//GBP CONVERSION RATES
float const gbpToUS = 1.29;
float const audToUS = .72;
float const bitToUS = 3696.11;
float const euroToUS = 1.14;
float const cadToUS = .75;
//////////////////////////
float amount;
printf("How much currency do you have? ");
scanf("%f", &amount); //use ampersand
//NOTHING BELOW PRINTS
printf("%f", amount);
printf("HEYYY");
printf("|| US || GBP || AUD || BIT || EUR || CAD ||");
}