My teacher assigned the class this:
Create a simple Game Loop for the game Mastermind. (Search the Internet to refresh your mind on how Mastermind is set up.)
Have your computer generate a random 5 digit number, as a string. Then the user must guess the number. Using the code:
1 = implies right Number, Right Place.
2 = implies right Number, Wrong Place.
0 = implies Wrong Number.
So the computer decides on 12345; the user guesses 11235; the computer should respond with 10221. Hint: Watch out for a double number like 11 when there is only one.
I am stuck though. I have my random numbers for the computer and I have my player guesses. I have also turned them into string. My problem is that idk how to access them from the convert_int_to_string(int computer_number[5]) function. can anyone help me?
#include <iostream>
#include <sstream>
#include <string>
#include <ctime>
#include <cmath>
#include <math.h>
#include <algorithm>
using namespace std;
void Welcome_Screen()
{
cout << "You are playing the text version of Mastermind." << endl << endl;
cout << "The rules are to guess the 5 digit number before your number of guesses run out. " << endl << endl;
cout << "The numbers run from 1 - 6 and there can be multiple numbers of the same number." << endl << endl;
cout << "1 implies the right number in the right place." << endl;
cout << "2 implies the right number but in the wrong place." << endl;
cout << "0 implies wrong number." << endl << endl;
cout << "Ready?? Here we go." << endl << endl;
system("pause");
system("cls");
}
string convert_int_to_string(int computer_number[5])
{
stringstream computer_numbers[5];
computer_numbers[0] << computer_number[0];
computer_numbers[1] << computer_number[1];
computer_numbers[2] << computer_number[2];
computer_numbers[3] << computer_number[3];
computer_numbers[4] << computer_number[4];
return computer_numbers[5].str();
};
string convert_player_guess_int_to_string(int player_guess[5])
{
stringstream player_numbers[5];
player_numbers[0] << player_guess[0];
player_numbers[1] << player_guess[1];
player_numbers[2] << player_guess[2];
player_numbers[3] << player_guess[3];
player_numbers[4] << player_guess[4];
return player_numbers[5].str();
};
int main()
{
Welcome_Screen();
srand(time(0));
int computer_number[5], player_guess[5];
int random_number1 = rand() % 6 + 1;
int random_number2 = rand() % 6 + 1;
int random_number3 = rand() % 6 + 1;
int random_number4 = rand() % 6 + 1;
int random_number5 = rand() % 6 + 1;
computer_number[0] = random_number1;
computer_number[1] = random_number2;
computer_number[2] = random_number3;
computer_number[3] = random_number4;
computer_number[4] = random_number5;
int number_of_guesses = 12;
cout << "The computer has made it's choices and set it's 5 numbers down. " << endl << endl;
cout << "What are your number guesses? (press enter after each number)" << endl << endl;
cout << "Guess 1: ";
cin >> player_guess[0];
cout << endl;
cout << "Guess 2: ";
cin >> player_guess[1];
cout << endl;
cout << "Guess 3: ";
cin >> player_guess[2];
cout << endl;
cout << "Guess 4: ";
cin >> player_guess[3];
cout << endl;
cout << "Guess 5: ";
cin >> player_guess[4];
cout << endl << endl;
convert_int_to_string(computer_number);
convert_player_guess_int_to_string(player_guess);
// how can I do the below??
// cout << "Computer numbers: " << computer_numbers[0] << computer_numbers[1] << computer_numbers[2] << computer_numbers[3] << computer_numbers[4] << endl;
// cout << "Player numbers: " << player_numbers[0] << player_numbers[1] << player_numbers[2] << player_numbers[3] << player_numbers[4] << endl;
//so this way I can make an if statement for my number of guesses loop????
system("pause");
return 0;
}