Jump to content

Generating random numbers!!

- - - - -

  • Please log in to reply
2 replies to this topic

#1
arjun2

arjun2

    Newbie

  • Members
  • Pip
  • 5 posts
I want to generate six numbers between 1-40 inclusive and
a player can bet six numbers between 1-40.
If he gets all the six numbers correct he win the JACKPOT!!

Here are some of my codes but what additional code should i need??

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

int main(void){

int nums[6];

int j;

srand(time(0));

for(j=0;j<6;j++)

nums[j]=(rand()%40)+1;


return 0;

}


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Well, it looks like you need to check for duplicates, get input guess from the user, and check for a win.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
You may want to remove a number that has been selected as a win. For example if num[0] = 1 and this is a winning number you can probably set num[0] to -1 to indicate the number was already chosen.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users