To try and bring in what I’ve learnt in the past from other languages, I’ve added a few methods already and changed how the sum/product is generated in order to allow further digits to be added easily
#include <iostream>
// Method for finding the sum of an input array of integers
int Sum(int inputs[]) {
int n, InputSum=0;
for ( n=0 ; n<3 ; ++n )
{
InputSum += inputs[n];
}
return InputSum;
}
// Method for finding the product of an input array of integers
int Product(int inputs[]) {
int m, InputProduct=1;
for ( m=0 ; m<3 ; ++m )
{
InputProduct *= inputs[m];
}
return InputProduct;
}
int main()
{
// Print welcome messages to the terminal
std::cout << "You awake as a woman with no name or memory.";
std::cout << std::endl;
std::cout << "The room you are in is bare and only the colour white.";
std::cout << std::endl;
std::cout << "There is a door with a keypad and screen. It looks like a code must be entered to open it.";
std::cout << std::endl;
// Declare 3 number code
const int CodeA = 4;
const int CodeB = 3;
const int CodeC = 2;
int CodeInputs [] = {CodeA, CodeB, CodeC};
int CodeSum = Sum(CodeInputs);
int CodeProduct = Product(CodeInputs);
// Print sum and product to the terminal
std::cout << std::endl;
std::cout << "+ There are " << (sizeof(CodeInputs)/sizeof(*CodeInputs)) << " numbers in the code" << std::endl;
std::cout << "+ The codes add up to: " << CodeSum << std::endl;
std::cout << "+ The codes multiply to give: " << CodeProduct << std::endl;
int GuessA, GuessB, GuessC;
// Request a guess code from the user
std::cin >> GuessA;
std::cin >> GuessB;
std::cin >> GuessC;
std::cout << "You entered: " << GuessA << GuessB << GuessC << std::endl;
int GuessInputs [] = {GuessA, GuessB, GuessC};
int GuessSum = Sum(GuessInputs);
int GuessProduct = Product(GuessInputs);
std::cout << "+ Your guess values add up to: " << GuessSum << std::endl;
std::cout << "+ Your guess values multiply to give: " << GuessProduct << std::endl;
if ((GuessSum == CodeSum) && (GuessProduct == CodeProduct))
{
std::cout << "The doors slide open.";
}
else
{
std::cout << "The screen reads 'ACCESS DENIED'. Try again.";
}
return 0;
}
// TODOs
// - prevent user from inputting anything but a value (use a regex?)
// - increase immersion with more output statements