表达式必须是L值

时间:2016-10-02 21:44:41

标签: c++ variables include int lvalue

我正在尝试制作一个可以识别直角三角形的公式。我对“a”和=符号有一些问题。

错误1:'=';左操作数必须是l值 错误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;
}

1 个答案:

答案 0 :(得分:0)

^运算符用于在C ++中获得逐位XOR。 你应该按照以下方式做到:

而不是a ^ 2 + b ^ 2 = c ^ 2语句,写一个像:

的块
    if(pow(c, 2) == pow(a, 2) + pow(b, 2))
        std :: cout << "true";
    else
        std :: cout << "false";
相关问题