Dec 10th, 2000, 10:40 AM
this is reall wierd,
I have this program, a mastermind game,
it should be working perfect... but it's not..
#include <iostream.h>
#include <stdlib.h>
int numguess = 0;
void getguess();
int main()
{
getguess();
return 0;
}
void getguess()
{
randomize();
int peg[2];
peg[0] = random(5) + 1;
peg[1] = random(5) + 1;
peg[2] = random(5) + 1;
int guess[2];
int rightpeg = 0;
int rightcolor = 0;
//checking for dupes
if (peg[0] == peg[1])
{
if (peg[1] > 1) peg[1]--;
else peg[1] ++;
}
if(peg[0] == peg[2])
{
if (peg[2] > 1) peg[2]--;
else peg[2] ++;
}
if (peg[1] == peg[2])
{
if (peg[2] > 1) peg[2]--;
else peg[2] ++;
}
cout << peg[0] << endl << peg[1] << endl << peg[2] << endl;
while(rightcolor < 3)
{
numguess++;
cout << "Guess " << numguess << ":" << endl;
cout << "First Peg: ";
cin >> guess[0];
cout << "Second Peg: ";
cin >> guess[1];
cout << "Third Peg: ";
cin >> guess[2];
if (guess[0] == peg[1])
rightpeg++;
if (guess[0] == peg[2])
rightpeg++;
if (guess[1] == peg[0])
rightpeg++;
if (guess[1] == peg[2])
rightpeg++;
if (guess[2] == peg[0])
rightpeg++;
if (guess[2] == peg[1])
rightpeg++;
if (guess[0] == peg[0])
{
rightpeg++;
rightcolor++;
}
if (guess[1] == peg[1])
{
rightpeg++;
rightcolor++;
}
if (guess[2] == peg[2])
{
rightpeg++;
rightcolor++;
}
cout << "You have " << rightpeg << " correct peg(s) and " << rightcolor;
cout << " correct color(s)" << endl;
rightcolor = 0;
rightpeg = 0;
}
cout << "You have broken the code in " << numguess << "guesses.";
}
lets say the order of the pegs is
2
1
3
I enter
2
1
3
it says all the pegs are correct, but only 2 colors are correct...
it seems to ignore the first number...
Any help is appreciated,
Thanks,
Dennis
I have this program, a mastermind game,
it should be working perfect... but it's not..
#include <iostream.h>
#include <stdlib.h>
int numguess = 0;
void getguess();
int main()
{
getguess();
return 0;
}
void getguess()
{
randomize();
int peg[2];
peg[0] = random(5) + 1;
peg[1] = random(5) + 1;
peg[2] = random(5) + 1;
int guess[2];
int rightpeg = 0;
int rightcolor = 0;
//checking for dupes
if (peg[0] == peg[1])
{
if (peg[1] > 1) peg[1]--;
else peg[1] ++;
}
if(peg[0] == peg[2])
{
if (peg[2] > 1) peg[2]--;
else peg[2] ++;
}
if (peg[1] == peg[2])
{
if (peg[2] > 1) peg[2]--;
else peg[2] ++;
}
cout << peg[0] << endl << peg[1] << endl << peg[2] << endl;
while(rightcolor < 3)
{
numguess++;
cout << "Guess " << numguess << ":" << endl;
cout << "First Peg: ";
cin >> guess[0];
cout << "Second Peg: ";
cin >> guess[1];
cout << "Third Peg: ";
cin >> guess[2];
if (guess[0] == peg[1])
rightpeg++;
if (guess[0] == peg[2])
rightpeg++;
if (guess[1] == peg[0])
rightpeg++;
if (guess[1] == peg[2])
rightpeg++;
if (guess[2] == peg[0])
rightpeg++;
if (guess[2] == peg[1])
rightpeg++;
if (guess[0] == peg[0])
{
rightpeg++;
rightcolor++;
}
if (guess[1] == peg[1])
{
rightpeg++;
rightcolor++;
}
if (guess[2] == peg[2])
{
rightpeg++;
rightcolor++;
}
cout << "You have " << rightpeg << " correct peg(s) and " << rightcolor;
cout << " correct color(s)" << endl;
rightcolor = 0;
rightpeg = 0;
}
cout << "You have broken the code in " << numguess << "guesses.";
}
lets say the order of the pegs is
2
1
3
I enter
2
1
3
it says all the pegs are correct, but only 2 colors are correct...
it seems to ignore the first number...
Any help is appreciated,
Thanks,
Dennis