Basic information regarding my computer:
Windows 7 x64 OS
8gb RAM
Using MingW compiler
So, everytime I run my program through the terminal after compiling it, it immediately stops responding. I can't seem to find the problem myself, so I'm asking for an extra set of eyes to point it out for me. I'm practically a beginner at C++ at the moment, so bear with me.
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
int main()
{
bool correct = false;
srand(time(NULL));
vector<string> guess;
vector<string> pallete;
vector<string> secret;
pallete.push_back("red");
pallete.push_back("green");
pallete.push_back("blue");
pallete.push_back("yellow");
for(int i = 0; i < 4 ; i++)
{
secret.push_back(pallete.at(rand()%secret.size()));
}
for(int j = 0; j < 4 ; j++)
{
guess.push_back(pallete.at(rand()%guess.size()));
}
vector<string> secretMem = secret;
cout << "the guess was:";
for(int x = 0; x<4; x++)
{
cout << guess[x] << endl;
}
while(correct == false)
{
int blackP = 0;
int whiteP = 0;
secret = secretMem;
for (int idxB = 0; idxB < secret.size(); idxB++)
{
if (guess[idxB] == secret[idxB])
{
secret[idxB] = "0";
guess[idxB] = "1";
blackP++;
}
}
for (int idxW = 0; idxW < secret.size(); idxW++)
for (int idyW = 0; idyW < guess.size(); idyW++)
{
if (secret[idxW] == guess[idyW])
{
secret[idxW] = "0";
guess[idxW] = "1";
whiteP++;
}
}
if (blackP == 4)
{
cout << "Congratulations you win." << endl << "The secret code was:"<< endl;
for(int y = 0; y<4; y++)
{
cout << secretMem[y] << endl;
}
correct = true;
}
else
cout << "you scored: " << blackP << " Black pegs" << "and" << whiteP << " White pegs" << endl;
}
return 0;
}
Also.... What is with this horrible code formatting.... I just can't get things to line up properly in the preview like it is when I'm writing it....