表达式必须是可修改的左值 Errror

Expression must be a modifiable lvalue Errror

本文关键字:Errror 修改 表达式      更新时间:2023-10-16

获取表达式一定是一个可修改的左值错误,我看过其他帖子仍然没有意义:/试图制作简单的温度转换器。

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

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

正如错误消息所述Expression must be a modifiable lvalue因此赋值左侧的值必须是变量。

正如S.M.上面所写的,你必须反过来处理你的任务。

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