The goal of this project is to implement a kind of game (MasterMind). This game consist into guess a player a hidden code (a number of 6 digits).
The player will try to guess the code; he has 5 chances to break the code. After each guess, your program provides the player two pieces of information about the current guess and the actual code. These pieces of information are:
1. The number of digits in the guess that are correct and in the right position.
2. The number of digits in the guess that are correct but in wrong position.
To develop this program, following these steps may help you :
1 – A function which split any number made of 6 digits into 6 different numbers
2 – A function which generate a secret code (number of 6 digits)
3 – A function which counts a number of correct digits in the code entered by the player, and provides to the player the two pieces of information above
4 – If the player reach the number of tries and doesn’t broke the code, print on the screen “you loose, the secret code is : …”, otherwise print “ Code broken after X tries”
Remarks:
-You have to validate each part (by using a main program) before stating the next
you can use only (Arrays ,Random , Pointers & loops ) !!!!!!!
you can use only (Arrays ,Random , Pointers & loops ) !!!!!!!
I think part of this project challenge is the restriction imposed above. It basically means you cannot use Standard C++ container, algorithm, iterator etc classes which is a shame actually cuz in the real working world, we use all Standard API to fasten our development. Time to market is important.
But all in all, it will be good to take us back to University era where we do assignment of such nature.
x % 10 returns the last digit of x.
x / 10 returns everything but the last digit.
if you put it in a loop, you can get all digits that way.
though honestly I see no reason to use an integer here. array of 6 chars would be better I think.
'what is the wrong' indeed. I don't see anything.. Except that you shouldn't call srand twice - you may get the same random numbers. Also, you first generate y[i], then ask the user to enter it. That makes no sense..