This is how my C++ beginner code looks like so far
#include <iostream>
#include <string>
using namespace std;
void PrintIntroduction(int Difficulty)
{
string text = "Welcome to the game: " + to_string(Difficulty);
//top of the Window
cout << (char)201;
for (int i = 0; i < text.length(); i++)
{
cout << (char)205;
}
cout << (char)187 << endl;
//middle of the window
cout << (char)186;
cout << text;
cout << (char)186 << endl;
//bottom of the window
cout << (char)200;
for (int i = 0; i < text.length(); i++)
{
cout << (char)205;
}
cout << (char)188 << endl;
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
cout << "You are a secret agent breaking into a secret server room..." << endl;
cout << "Enter the correct code to continue..." << endl;
int CodeA = rand(), CodeB = rand(), CodeC = rand(), CodeSum = 0, CodeProduct = 0;
int GuessA = 0, GuessB = 0, GuessC = 0, GuessSum = 0, GuessProduct = 0;
CodeSum = CodeA + CodeB + CodeC;
CodeProduct = CodeA * CodeB * CodeC;
cout << endl;
cout << "There are 3 numbers in the code" << endl;
cout << "The codes add-up to: " << CodeSum << endl;
cout << "The codes multiply to give: " << CodeProduct << endl;
cin >> GuessA;
cin >> GuessB;
cin >> GuessC;
GuessSum = GuessA + GuessB + GuessC;
GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
cout << "you win" << endl;
return true;
}
else
{
cout << "you loose" << endl;
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
cin.clear();
cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
}
cout << "Mission success" << endl;
return 0;
}