I am planning to create a simple bulls and cows( also know as mastermind board game) in C.The computer is supposed to make 4 digit code in which the allowed digits are 1,2,3,4,5,and 6 ! 0,7,8,9 are to omitted !! How do I make the computer create such a 4 digit number? I know about rand() function !! But how do I make it omit those 4 digits?
Jump to Post
rand() can give you a specific range of random numbers. Just set it up for 1 to 5, four times.
Inside a loop, you can put the "number" together, from those digits if you want:
5 * 10^0 +
3 * 10^1 +
All 8 RepliesReply to this topic
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.