Lottery game

This is a discussion on Lottery game within the C++ Programming forums, part of the General Programming Boards category; Hey, I need to make a 'balls in a rolling cage' lottery game; it plays like this (from teacher's exemple): ...

  1. #1
    blah!
    Join Date
    Nov 2005
    Posts
    3

    Lottery game

    Hey, I need to make a 'balls in a rolling cage' lottery game; it plays like this (from teacher's exemple):

    -Program shows 2 numbers from 0 to 21 (let's call them number1a and number2a)
    -Then, the user selects how many times he/she wants to roll the cage (containing the 'number balls')
    -Program picks 2 random numbers from 0 to 21 (number1b and number2b)
    -Then, the program checks if those two newly picked up numbers are the same as the first ones. (if number1a==number1b && number2a==number2b)
    So if both numbers are the same (before and after the rolling), then the user wins.
    If one number is picked again and the second is not, then the user loses.

    ie:

    Program picks up 7 and 19.
    Program asks me how many rolls? I want it to roll 10x.
    Program picks 7 and 19.
    YAY! I won!

    or...
    Program picks 7 and 19.
    Program asks me how many rolls? I want it to roll 100x.
    Program picks 7 and 13. <=> Program picks 2 and 8.
    Sorry, better luck next time.

    The goal of using the rolling thing is that the more rolls you make, the less change you get the same numbers.

    Hoping you guys understood the point this game , here's my current code:

    Code:
    // Lottery game
    #include<iostream>
    #include<cstdlib>
    #include<ctime>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main()
    {
    	double number1a, number2a, number1b, number2b, xRoll;
    			
    			cout << "Welcome to the Lottery Game!" << endl << endl;
    			number1 = rand()%21+1;
    			number2 = rand()%21+1;
    			if (number1 == number2){
    			number1 = rand()%21+1;
    			number2 = rand()%21+1;
    			cout << "The first number is: " << number1a << endl;
    			cout << "The second number is: " << number2a << endl;
    			cout << "How many rolls?: " << xRoll;
    			[No idea what's next here...]
    				cout << "The first picked number is: " << number1b << endl;
    				cout << "The second picked number is: " << number2b << endl;
    				if (number1a == number1b && number2a == number2b){
    				cout << "CONGRATULATIONS! You won the lottery!" << endl;
    				}
    				else
    				cout << "Sorry, you lost. Better luck next time.";
    			}
    			else{
    			cout << "The first number is: " << number1 << endl;
    			cout << "The second number is: " << number2 << endl;
    			cout << "How many rolls?: " << xRoll;
    			[No idea what's next here...]
    				cout << "The first picked number is: " << number1b << endl;
    				cout << "The second picked number is: " << number2b << endl;
    				if (number1a == number1b && number2a == number2b){
    				cout << "CONGRATULATIONS! You won the lottery!" << endl;
    				}
    				else
    				cout << "Sorry, you lost. Better luck next time.";
    			}
    
    		return 0;
    }
    Sorry if it's bloated with useless lines...

    Also, I keep getting the same picked numbers frequencies... like on the first play, i get numbers 2 and 11, then I close the program, re-open it, and it gives me 2 and 11 again on 2nd play. 3rd play, same thing...
    I looked in my book and it suggests to use srand to generate new frequencies at each time. Tried that; no success

    -Thanks in advance

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  3. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 04:48 PM
  4. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21