I've started programming a "Bulls and Cows" game.I got through the two player mode(which is easy). Now for the single player, I know how to generate a random number but I have a problem in generating a number with distinct digits(4-digit number)?Can anyone help me out?
Example:The number can be 1234 not 1133 or 2448.
[code]
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
void main()
{
char guess[10], word[10];
int turns, a, b, bulls, cows;
clrscr();
cout<<"Welcome to Bulls & Cows \n\nPlayer 1, enter the letters(distinct) of your word: ";
cin.getline(word,sizeof(word));
clrscr();
cout<<"\nPlayer2, please get ready.";
for(turns=1;turns<=10;turns++)
{
bulls=0;cows=0;
cout<<"\nEnter Guess : "<<turns;
cin.getline(guess,sizeof(guess));
for(a=0;a<4;a++)
{
if(guess[a]==word[a])
{
bulls++;
}
else
{
for(b=0;b<4;b++)
{
if(guess[a]==word[b])
{
cows++;
}
}
}
}
if(bulls==4)
{
cout<<"\nYou are Victorious!\n";
break;
}else
{
cout<<"\nBulls ="<<bulls<< "Cows ="<<cows;
}
}
getch();
}
[\code]