Thread: Write a lucky pick program

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    3

    Write a lucky pick program

    May i know how to write a lucky pick program in dos mode.

    got a group of number 1 to 52. got 6 group to select it. and each time when the group get the number it will obliterate it from the number group.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    actually i'm newbie i dun know where should i start.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That's a shame.

    Do you know how to pick numbers randomly?
    Do you know how to check whether one number is the same as another number?

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    here's one that uses the "Fischer-Yates shuffle":

    Code:
     #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main() {
    	int x, ray[52], i, y, tmp;
    	for (i=0;i<52;i++) ray[i]=i;
    	srand(time(0));
    	for (i=51;i>=0;i--) {
    		x=RAND_MAX/(i+1);
    		y=rand(); y/=x;
    		if (y==i) continue;
    		tmp=ray[i];
    		ray[i]=ray[y];
    		ray[y]=tmp;
    	}
    	for (i=0;i<6;i++) printf("%d\n",ray[i]);
    	return 0;
    }
    Last edited by MK27; 11-30-2008 at 11:10 AM.

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    i want to make it the lucky pick number's row that i want. and how to sort the number ascending

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Newbie needs help..
    By xpress urself in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2007, 07:22 PM
  3. how could i write this program: cat < apa | wc | wc > bepa
    By strugglingman in forum C Programming
    Replies: 2
    Last Post: 04-26-2006, 04:40 PM
  4. Replies: 1
    Last Post: 10-13-2004, 12:15 PM
  5. Challenge to write a program
    By Twisted.alice in forum A Brief History of Cprogramming.com
    Replies: 40
    Last Post: 05-15-2003, 12:00 PM