Hey guys here’s what I got.
I already added some functions that weren’t in the next couple of videos haha (didn’t notice there were sectione about them… ^^
#include <iostream>
#include <string>
#include <array>
#include <ctime>
int Product(std::array<int, 3> collection);
int Sum(std::array<int, 3> collection);
std::array<int, 3> InputGuess(int);
int main()
{
std::srand(std::time(nullptr));
std::cout << "You are a secret agent breaking into a secure server room..." << std::endl << "Enter secret code to continue..." << std::endl;
std::array<int, 3> ListOfNumbersToGuess = {std::rand() % 9 + 1, std::rand() % 9 + 1, std::rand() % 9 + 1};
int ProductClue = Product(ListOfNumbersToGuess);
int SumClue = Sum(ListOfNumbersToGuess);
std::cout << "The numbers in the code are such as the sum makes " << SumClue << " and the product makes " << ProductClue << std::endl;
std::array<int, 3> ListOfNumbersInput = InputGuess(3);
int ProductGuess = Product(ListOfNumbersInput);
int SumGuess = Sum(ListOfNumbersInput);
if (SumClue == SumGuess && ProductClue == ProductGuess) {
std::cout << "You win";
}
else {
std::cout << "Too bad";
}
return 0;
}
int Product(std::array<int, 3> Collection) {
int Result = 1;
for (int Value : Collection) {
Result *= Value;
}
return Result;
}
int Sum(std::array<int, 3> Collection) {
int Result = 0;
for (int Value : Collection) {
Result += Value;
}
return Result;
}
std::array<int, 3> InputGuess(int Limit) {
std::array<int, 3> Input = {0, 0, 0};
for (int i = 0; i < Limit; i++) {
std::cout << "Input N° " << i << " : ";
int Number;
std::cin >> Number;
Input[i] = Number;
std::cout << std::endl;
}
return Input;
}