Using if and else

#include

int main()

{

std :: cout<<"Chao may thang ngu\n";  

std :: cout << std :: endl;

std :: cout<<"Nhap mat khau vo di thang ngu...";

//declare 3 code number

const int CodeA=4;

const int CodeB=3;

const int CodeC=2;

const int CodeSum = CodeA + CodeB + CodeC;

const int CodeProduct = CodeA * CodeB * CodeC;

//print sum and product to the terminal

std :: cout << std :: endl;

std :: cout << "there are three num in the code" << std::endl;

std :: cout <<"the code add up to :" << CodeSum << std :: endl;

std :: cout <<"the code has product of 3 num :"<< CodeProduct << std :: endl;

int GuessA, GuessB, GuessC;

std :: cin >> GuessA >> GuessB >> GuessC ;

std :: cout <<"You entered : " << GuessA << GuessB << GuessC;

std :: cout << std :: endl;

int GuessSum = GuessA + GuessB + GuessC;

//std :: cout << "Sum of them : " << GuessSum;

int GuessProduct = GuessA * GuessB * GuessC;

//std :: cout << "Product of them : " << GuessProduct;



if(GuessSum == CodeSum && GuessProduct == CodeProduct )

{

    std :: cout << "You win!\n ";

}

else

{

    std :: cout << "You lose!\n ";

}

return 0;

}

1 Like

Good job using it and else

Privacy & Terms