表达式必须是 L 值
Expression must be an L value
我正在尝试制作一个可以识别直角三角形的公式。我在使用 "a" 和 = 符号时遇到一些问题。
错误一:'=';左操作数必须是左值。
错误 2:"a"。表达式必须是可修改的左值。
有什么帮助吗?
#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int a;
int b;
int c;
cout << "Input value for A." << endl;
cin >> a;
cout << "Input value for B. " << endl;
cin >> b;
cout << "Input value for C. " << endl;
cin >> c;
a ^ 2 + b ^ 2 = c ^ 2;
return 0;
}
^
运算符用于在 C++ 中获取按位异或。
您应该按照以下方式进行操作:
而不是 a ^ 2 + b ^ 2 = c ^ 2
语句,写一个像这样的块:
if(pow(c, 2) == pow(a, 2) + pow(b, 2))
std :: cout << "true";
else
std :: cout << "false";
我正在尝试制作一个可以识别直角三角形的公式。我在使用 "a" 和 = 符号时遇到一些问题。
错误一:'=';左操作数必须是左值。
错误 2:"a"。表达式必须是可修改的左值。
有什么帮助吗?
#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int a;
int b;
int c;
cout << "Input value for A." << endl;
cin >> a;
cout << "Input value for B. " << endl;
cin >> b;
cout << "Input value for C. " << endl;
cin >> c;
a ^ 2 + b ^ 2 = c ^ 2;
return 0;
}
^
运算符用于在 C++ 中获取按位异或。
您应该按照以下方式进行操作:
而不是 a ^ 2 + b ^ 2 = c ^ 2
语句,写一个像这样的块:
if(pow(c, 2) == pow(a, 2) + pow(b, 2))
std :: cout << "true";
else
std :: cout << "false";