Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 17th, 2007, 05:28 AM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Honour
Default Lottery Winners Program Urgent Help Needed!

Hi !

I'm having a great deal of problems with this programming project. I am due to code a Lottery winners exercise with the following instructions:

Lottery Winners program.
A lottery ticket buyer purchases ten tickets a week, always playing the same ten 5-digit "lucky" combinations. Write a program that initializes an array with these numbers and then lets the player enter this week's winning 5-digit number. The program should perform a linear search through the list of the player's numbers and report whether or not one of the tickets is a winner this week. Here are the numbers:

13579 26791 26792 33445 55555
62483 77777 79422 85647 93121

Extend this challenge by permitting any number of lottery entries, and using a pointer instead of a fixed array. The general idea is this:

§ Declare your array of numbers as a pointer to int, rather than as a fixed array of int.

§ Have the first number entered by the user of your program be the number of entries. Let this number be N.

§ Allocate space for the array using new.

§ The remaining input should be the N lottery numbers.

§ Proceed with the rest of the program to carry out binary searches in your array. You need a loop that repeatedly asks for a number, then says whether its a “winner” or not. Enter a 0 to stop the loop and return from the program.

§ Release the array space before returning using delete.

Testing this program by typing in all the numbers can be challenging. Instead, consider writing the “user entries” as a text file, then, in Visual Studio:

· Select Project/Settings/Debug.

· Enter the name of your text file in the Program Arguments panel, preceded by “<”, like this:

< TextFileName.txt

· Your text file should be in the same directory as your project. This will happen if you use Visual Studio to open a text file, fill it in with the editor, then save it with a simple name.

This project is due in a day! I have become sick prior to starting this project, but trying to figure this out and given all the attempts I have made I have put myself in an even worst situation. This is driving me insane!
I need help, please! Anything is appreciated!
Reply With Quote
  #2 (permalink)  
Old April 24th, 2007, 11:25 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

Anyone here can help you...

Your problem is that you are asking us to do it for you...

Post your code that you have done...

Tell us what you think is wrong with it and we will help...

~ Geo

~ Don't take life too seriously, you'll never get out alive!
Reply With Quote
  #3 (permalink)  
Old May 19th, 2007, 04:47 AM
Authorized User
 
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Peter_APIIT
Default

Here is the program :
/* A Lottery Program which uses to check
   lottery buyer is same as the result
*/

#include<iostream>

using std::cout;
using std::endl;
using std::cin;




int main(int argc, char *argv[])
{
    int loop, counter = 10;
    int thisresult[10] = {13579, 26791, 26792, 33445,
                          55555, 62483, 77777, 79422,
                          85647, 93121};
    // This week lottery result

    int number_lottery;
    // Number of user lottery

    cout << "How many number of lottery : ";
    cin >> number_lottery;

    int *user_lottery = new int[number_lottery];

    for (loop=0;loop<number_lottery;loop++)
    {
        cout << "Enter the lottery Number : ";
        cin >> *(user_lottery + loop);
    }

    cout << "\n\nComparison is begin shortly\n\n";
    counter = 10;
    while(counter > 0)
    {
        cout << counter << "!" << "\n";
        counter--;
    }

    // -------------------------------------
    // Comparison Part/Linear Search

    for (loop=0;loop<10;loop++)
    {
        if ( *(user_lottery + loop) == thisresult[loop] )
        {
            cout << "\n\nCongratulations, you are one of the winner";
            cout << "\n\nThe winning ticket is " << *(user_lottery + loop);
        }
    }

    delete [] user_lottery;

    return 0;
}

/* I don't know binary search, if you know
   please email me as follow : [email protected]
   Your help is greatly appreciated by me
*/



Linux is the best OS in the world.
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Special Program Needed carlo0099 Pro PHP 0 March 16th, 2008 09:41 PM
Lottery Program Help...I'm using 2005 Visual Basic psycoblaster VB.NET 2002/2003 Basics 13 May 23rd, 2007 09:13 PM
Help needed on a program BRS0903 Visual Basic 2005 Basics 1 June 14th, 2006 11:02 AM
writing a lottery program in C++ captlem66 VB.NET 2002/2003 Basics 2 October 13th, 2004 02:50 AM
Visual basic.net (Lottery program) Brettvan1 VB.NET 2002/2003 Basics 10 October 1st, 2004 08:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.