C 错误必须是可修改的左值
我试图用C语言制作一个简单的货币转换器,但由于某种原因,它总是给我一个错误“error must a modifiable levvalue”。 我已经检查了我的代码,没有发现任何问题。有什么帮助吗C 错误必须是可修改的左值,c,C,我试图用C语言制作一个简单的货币转换器,但由于某种原因,它总是给我一个错误“error must a modifiable levvalue”。 我已经检查了我的代码,没有发现任何问题。有什么帮助吗 #include <stdio.h> #include <stdlib.h> void main(){ float jod_usd=1.41, usd_jod=0.71, jod_eur=1.26, eur_jod=0.8, currency;
#include <stdio.h>
#include <stdlib.h>
void main(){
float jod_usd=1.41, usd_jod=0.71, jod_eur=1.26, eur_jod=0.8, currency;
char ic;
int f;
printf("Enter the number of your conversion option to continue...\n1- Convert from JOD\n2- Convert to JOD\n");
scanf("%d",&f);
printf("Enter the character of your second currency to continue...\nU - - USD\nE - - EUR\n");
scanf("%c",&ic);
printf("Enter your amount:\n");
scanf("%f",¤cy);
if(f==1&&(ic='U'||ic='u')){
printf("%.2f JOD - - %.2f USD\n",currency,(currency*jod_usd));
}
if(f==1&&(ic='E'||ic='e')){
printf("%.2f JOD - - %.2f EUR\n",currency,(currency*jod_eur));
}
if(f==0&&(ic='E'||ic='e')){
printf("%.2f EUR - - %.2f JOD\n",currency,(currency*eur_jod));
}
if(f==0&&(ic='U'||ic='u')){
printf("%.2f USD - - %.2f JOD\n",currency,(currency*usd_jod));
}
system("pause");
}
#包括
#包括
void main(){
浮动工作日美元=1.41,美元=0.71,工作日欧元=1.26,欧元=0.8,货币;
字符ic;
int f;
printf(“输入要继续的转换选项的编号…\n1-从JOD转换\n2-转换为JOD\n”);
scanf(“%d”、&f);
printf(“输入第二种货币的字符以继续…\nU--USD\nE--EUR\n”);
scanf(“%c”和“ic”);
printf(“输入您的金额:\n”);
scanf(“%f”和货币);
如果(f==1&(ic='U'| | ic='U')){
printf(“%.2f工作日---%.2f美元”,货币,(货币*工作日美元));
}
如果(f==1&(ic='E'|ic='E')){
printf(“%.2f工作日---%.2f欧元”,货币,(货币*工作日欧元));
}
如果(f==0&(ic='E'| ic='E')){
printf(“%.2f欧元---%.2f工作日”,货币,(货币*欧元工作日));
}
如果(f==0&(ic='U'|ic='U')){
printf(“%.2f美元---%.2f工作日”,货币,(货币*美元工作日));
}
系统(“暂停”);
}
TL;DR使用=
而不是=
的错误导致了这一点
首先,您正在无意中更改ic
的值
第二,由于运算符优先
(ic='U'||ic='u')
与
((ic='U'||ic) = 'u')
其中,
(ic='U'| ic)
的结果是而不是一个左值。你确定这不仅仅是一个简单的错误吗?您通常不会在条件中指定。如果我解决了这个问题,你会得到一些程序流程:
Enter the number of your conversion option to continue...
1- Convert from JOD
2- Convert to JOD
1
Enter the character of your second currency to continue...
U - - USD
E - - EUR
Enter your amount:
代码
#包括
#包括
void main(){
浮动工作日美元=1.41,美元=0.71,工作日欧元=1.26,欧元=0.8,货币;
字符ic;
int f;
printf(“输入要继续的转换选项的编号…\n1-从JOD转换\n2-转换为JOD\n”);
scanf(“%d”、&f);
printf(“输入第二种货币的字符以继续…\nU--USD\nE--EUR\n”);
scanf(“%c”和“ic”);
printf(“输入您的金额:\n”);
scanf(“%f”和货币);
如果(f==1&&(ic==U'| | ic==U')){
printf(“%.2f工作日---%.2f美元”,货币,(货币*工作日美元));
}
如果(f==1&&(ic==E'| | ic==E')){
printf(“%.2f工作日---%.2f欧元”,货币,(货币*工作日欧元));
}
如果(f==0&(ic==E'| | ic==E')){
printf(“%.2f欧元---%.2f工作日”,货币,(货币*欧元工作日));
}
如果(f==0&&(ic==U'| | ic==U')){
printf(“%.2f美元---%.2f工作日”,货币,(货币*美元工作日));
}
系统(“暂停”);
}
(ic='U'| ic
。。。。hmmmm@SouravGhosh我不是,我只是用大写字母写的,以表明这是关于C编程的。如果听起来像这样,我很抱歉,我会编辑它。正如苏拉夫·戈什指出的,在测试ic
的值时,使用==
而不是=
。那些ic=|ic=
都不好@Cor@Cor更好现在,这仍然不是一个很好的标题。:)哦!我还以为你用了一个而不是两个符号呢!这门语言还是新的,在大学里学的。非常感谢!:)我刚刚测试了一下,得到了同样的结果。。老实说,我不太确定是什么原因造成的。有什么想法吗?
#include <stdio.h>
#include <stdlib.h>
void main(){
float jod_usd=1.41, usd_jod=0.71, jod_eur=1.26, eur_jod=0.8, currency;
char ic;
int f;
printf("Enter the number of your conversion option to continue...\n1- Convert from JOD\n2- Convert to JOD\n");
scanf("%d",&f);
printf("Enter the character of your second currency to continue...\nU - - USD\nE - - EUR\n");
scanf("%c",&ic);
printf("Enter your amount:\n");
scanf("%f",¤cy);
if(f==1 && (ic=='U' || ic=='u')){
printf("%.2f JOD - - %.2f USD\n",currency,(currency*jod_usd));
}
if(f==1&&(ic=='E'||ic=='e')){
printf("%.2f JOD - - %.2f EUR\n",currency,(currency*jod_eur));
}
if(f==0&&(ic=='E'||ic=='e')){
printf("%.2f EUR - - %.2f JOD\n",currency,(currency*eur_jod));
}
if(f==0&&(ic=='U'||ic=='u')){
printf("%.2f USD - - %.2f JOD\n",currency,(currency*usd_jod));
}
system("pause");
}