【问题标题】:Expression must be a modifiable lvalue Errror表达式必须是可修改的左值错误
【发布时间】:2019-10-13 01:11:10
【问题描述】:

得到表达式必须是一个可修改的左值错误,我看了其他帖子仍然没有意义:/尝试制作简单的温度转换器。

1>C:\Users\whatsupnigeh\Desktop\Stuff\asmgodtm\Temperature_Converter\Temperature_Converter\Main.cpp(30,30):错误 C2106:'=':左操作数必须是左值

#include <iostream>
#include <Windows.h>
#include <math.h>
using namespace std;
float final_temp;

int main()
{
    SetConsoleTitleA("Temperature Converter");

    cout << "{1} Fahrenheit -> Celsius" << endl;
    cout << "{2} Celsius -> Fahrenheit" << endl << endl;

    cout << "Selection: " << endl;
    int choice;
    cin >> choice;

    if (choice == 1)
    {
        cout << "Enter F*: " << endl << endl;
        float f;
        cin >> f;
        f - 32 * 5 / 9 = final_temp;
        cout << final_temp;

    }
    if (choice == 2)
    {
        cout << "Enter C*: " << endl << endl;
        float c;
        cin >> c;
        c * 9 / 5 + 32 = final_temp;
        cout << final_temp;
    }
    else
    {
        return 0;
    }

    Sleep(3000);
    return 0;
}

【问题讨论】:

  • f - 32 * 5 / 9 = final_temp; --> final_temp = f - 32 * 5 / 9;

标签: c++


【解决方案1】:

由于错误消息指出Expression must be a modifiable lvalue,因此赋值左侧的值必须是变量。

作为 S.M.上面写了你必须把你的作业反过来。

f - 32 * 5 / 9 = final_temp; 应该是final_temp = ((f - 32) * 5) / 9.;

【讨论】:

  • 错误的优先级。应该是final_temp = (f - 32) * 5 / 9;
  • @stark 感谢您的更正。我刚刚从上面的评论中复制了更正!
  • 您应该经常检查您的答案是否正确。许多问题都有多个问题。
猜你喜欢
  • 1970-01-01
  • 2014-12-15
  • 2015-03-30
  • 1970-01-01
  • 1970-01-01
  • 2020-07-07
  • 2021-10-02
  • 1970-01-01
相关资源
最近更新 更多