mercredi 18 mai 2022

If statement giving parenthesis error in my triangle exercise

Learning C++ and doing a basic triangle exercise.

Can anyone check my code if I done everything right and explain why I am getting this error: suggest parenthesis around ‘&&’ within ‘||’

#include <iostream>

int main()
{
    // enter 3 numbers for sides of triangle
    int a, b, c;
    std::cout << "Input three numbers: " << std::endl;
    std::cin >> a;
    std::cin >> b; 
    std::cin >> c;
  
    // check what kind of traingle it is and output result
    if(a == b  && b == c){
        std::cout << "You have an equalateral triangle." << std::endl;
    }else if(a == b && b !=c || a!=b && b==c || a==c && b!=c){
        std::cout << "You have an iso triangle." << std::endl;
    }else{
        std::cout << "You have an scalene triangle." << std::endl;
    } 
}

Aucun commentaire:

Enregistrer un commentaire