My code has a successful build, but when I run it and type in my 5 numbers, it breaks. Any clue as to how I can fix it??? Much help will be appreciated.
#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;
int response[3], help_numbers[5];
response[0] = 0;
response[1] = 1;
response[2] = 2;
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;
string string_computer_numbers = convert_int_to_string(computer_number);
string string_player_numbers = convert_player_guess_int_to_string(player_guess);
if (string_computer_numbers[0] == string_player_numbers[0] && string_computer_numbers[1] == string_player_numbers[1] && string_computer_numbers[2] == string_player_numbers[2] && string_computer_numbers[3] == string_player_numbers[3] && string_computer_numbers[4] == string_player_numbers[4])
{
cout << "You got the computer's numbers!!!! =)" << endl << endl;
}
else if (string_player_numbers[0] < 1 && string_player_numbers[0] > 6 && string_player_numbers[1] < 1 && string_player_numbers[1] > 6 && string_player_numbers[2] < 1 && string_player_numbers[2] > 6 && string_player_numbers[3] < 1 && string_player_numbers[3] > 6 && string_player_numbers[4] < 1 && string_player_numbers[4] > 6)
{
help_numbers[0] = response[0];
help_numbers[1] = response[0];
help_numbers[2] = response[0];
help_numbers[3] = response[0];
help_numbers[4] = response[0];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] != string_player_numbers[2] && string_computer_numbers[0] != string_player_numbers[3] && string_computer_numbers[0] == string_player_numbers[4])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] != string_player_numbers[2] && string_computer_numbers[0] == string_player_numbers[4])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] != string_player_numbers[2] && string_computer_numbers[0] == string_player_numbers[3])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] == string_player_numbers[4])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] == string_player_numbers[3])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] == string_player_numbers[2])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] == string_player_numbers[4])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] == string_player_numbers[3])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] == string_player_numbers[2])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] != string_player_numbers[0] && string_computer_numbers[0] == string_player_numbers[1])
{
help_numbers[0] = response[2];
}
else if (string_computer_numbers[0] == string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[1] && string_computer_numbers[0] == string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[2] && string_computer_numbers[0] == string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[3] && string_computer_numbers[0] == string_player_numbers[0] && string_computer_numbers[0] != string_player_numbers[4])
{
help_numbers[0] = response[1];
}
cout << "Computer Numbers: " << computer_number[0] << computer_number[1] << computer_number[2] << computer_number[3] << computer_number[4] << endl << endl;
cout << "Player Guesses: " << string_player_numbers[0] << string_player_numbers[1] << string_player_numbers[2] << string_player_numbers[3] << string_player_numbers[4] << endl << endl;
system("pause");
return 0;
}