Here is the code:
#include <iostream>
int main()
{
// Print the story and what to do in the terminal
std::cout<< "You are locked into a room with a captivated cobra!";
std::cout<<std::endl;
std::cout<< "You have to enter the correct numbers, otherwise the cobra will be released and poison you to death..." <<std::endl;
const int CodeA = 2;
const int CodeB = 1;
const int CodeC = 3;
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<<"+ You have to enter 3 numbers" << std::endl;
std::cout<< "+ The numbers add up to: " << CodeSum;
std::cout<<std::endl;
std::cout<< "+ The numbers multiply to give: " << CodeProduct;
std::cout<<std::endl;
std::cout<<std::endl;
int GuessA;
int GuessB;
int GuessC;
std::cin >> GuessA;
std::cin >> GuessB;
std::cin >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "You enterd the coorect code! The cobra is kept inside, but it is getting hungry!";
}
else
{
std::cout << "Oh no, you entred the wrong code! The cobra is released and bytes you to death!";
}
return 0;
}
This happens, when you win:
And this when you loose: