#include <iostream>
int main()
{
//Starting message
std::cout << "You are an adventurer diving dep int othe goblin caves.\n";
std::cout << "Before you lies a chest with a combination lock.\n";
std::cout << "Unlock the chest to gather the loot and unlock the next dungeon level.\n";
std::cout << "Good luck adventurer.\n" << std::endl;
//The digits
const int CodeA = 5;
const int CodeB = 5;
const int CodeC = 3;
//Multiplying and adding the numbers
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Out puting the product and sum
std::cout << " # There are three numbers you must figure out:\n";
std::cout << " # The code add up to: " << CodeSum << std::endl; //<< product << std::endl; (This works as well if you want to do it on one line.)
std::cout << " # The code has a product of: " << CodeProduct << std::endl;
int GuessA, GuessB, GuessC;
std::cout << std::endl;
std::cout << "First Number: "; std::cin >> GuessA;
std::cout << "Second Number: "; std::cin >> GuessB;
std::cout << "Third Number: "; std::cin >> GuessC;
std::cout << std::endl << "You have entered the code: " << GuessA << " " << GuessB << " " << GuessC;
std::cout << std::endl;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "You correctly guess the code and open the chest!\n";
}
else
{
std::cout << std::endl;
std::cout << "You have put in the incorrect code and the goblins have captured you.\n";
std::cout << "Better luck next time adventurer.\n";
}
return 0;
}
A look at my code after finishing this lesson.