为什么0分啊,求助

P1422 小玉家的电费

qyb0713 @ 2024-03-10 10:01:20

#include<bits/stdc++.h>

using namespace std;

int main()

{

    char x,y;

    cin>>x;

    if (x<=150){

    y==x*0.4463;

    printf("%1f",y);}

    if(x>150&&x<=400){

    y==150*0.4463+(x-150)*0.4663;

    printf("%1f",y);}

    if(x>400){

    y==150*0.4463+(x-150)*0.4663+(x-400)*0.5663;

    printf("%1f",y);}

    return 0;

}

by ciky @ 2024-03-10 10:34:52

我没理解错的话 你第15 21 27行是要赋值吧?谁教你赋值用==啊?我语气不太好 不好意思啊


by Zebraj @ 2024-03-14 20:25:34

#include<bits/stdc++.h>

using namespace std;

int main()

{

    char x,y;

    cin>>x;

    if (x<=150){

    y==x*0.4463;//??? if执行语句写判断表达式?

    printf("%1f",y);}

    if(x>150&&x<=400){

    y==150*0.4463+(x-150)*0.4663;//这也是

    printf("%1f",y);}

    if(x>400){

    y==150*0.4463+(x-150)*0.4663+(x-400)*0.5663;//还有这

    printf("%1f",y);}

    return 0;

}

“==”是关系运算符,而“=”是赋值运算符


|