dimanche 10 janvier 2021

i have applied if condition but it never runs the code in if else part i am using c++ [closed]

Here it is i have applied a if condition that if i enter 1 i can do a+b whole square equation and if i enter 2 i can do a-b whole square equation but when i run it never runs the code in if else condition when i enter2.

#include<iostream>
using namespace std;

int main(){
    int idnt;
    int a;
    int b;
    int asqr;
    int bsqr;
    int twoab;
    int answerp;
    int answern;
    cout << "Welcome To Math Identities \n";
    cout << "Insert the values of the variables \n";
    cin >> a;
    cin >> b;
    asqr = a*a;
    bsqr = b*b;
    twoab = 2*a*b;
    cin >> idnt;
    if ((idnt = 1)){
    answerp = asqr+bsqr+twoab;
    cout << "Your answer is \n";
    cout << asqr;
    cout << "+";
    cout << bsqr;
    cout << "+";
    cout << twoab;
    cout << "=";
    cout << answerp;}
    else if ((idnt=2)){
        answern = asqr + bsqr - twoab;
        cout << "Your answer is \n";
        cout << asqr;
        cout << "+";
        cout << bsqr;
        cout << "-";
        cout << twoab;
        cout << "=";
        cout << answern;
    }
}

Aucun commentaire:

Enregistrer un commentaire