I have hard project .

Hi every one I have a hard project which is :

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 ) !!!!!!!

Last edited on
Sounds like an interesting project. Thanks for informing us.
Good luck with your homework. It's not that hard..
If you have any problems with it, just ask.
What you call hard I call interesting. Try changing your mindset. I need some projects to do myself so thanks for the idea!
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.
Last edited on
so any solution ؟

can any help me to do it .
You remind me of this guy (http://cplusplus.com/forum/general/33511/)

Do it yourself and ask specific question to your problem!
O.K

So how can split any number made of 6 digits into 6 different numbers ?

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.
ok

but if i use x % 100 in example 234 he will give me the last number it will be 2

and if i modified it to x % 10 it will gave me 23 not 3 what should i do to get last number not the last two number .
I think you need to read up on modulus operator. x %100 will give value of 0..99 assume x >= 0

So 234 % 100 will give 34

So 234 % 10 will give 4

So the value of a modulus operation is based on the the denominator value from range 0..denominator-1 inclusive assume numerator >= 0

After understanding on modulus operator works, try to use or revised it to your own requirement needs.
cplspls wrote:
but if i use x % 100 in example 234 he will give me the last number it will be 2

and if i modified it to x % 10 it will gave me 23 not 3 what should i do to get last number not the last two number .
No. Like hamsterman said:

x % 10 -> 4
x / 10 -> 23
x % 10 -> 3
x / 10 -> 2
x % 10 -> 2
x / 10 -> 0

you need a loop that ends when the value is 0 and that pair
x %10
x / 10
within that loop to get the digits from a number. (I did that multiple times)
what is the wrong ?

#include<iostream>
#include<ctime>
#include<cstdlib>

using namespace std;
int main() {

int x[6],y[6];

srand(time(0));
for( int i=0;i<6;i++){
x[i]=rand()%10;

cout<<x[i];
}
srand(time(0));
for (int j=0;j<6;j++){
y[j]=rand()%10;

cin>>y[j];
}
return 0;
}
Last edited on
'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..
thanks .

Topic archived. No new replies allowed.