473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Lotto Numbers - Check how many matches there are. Please Help..

K. I'm kinda totally lost on how to go about this....

Here's the Question:
------------------------------
Write a program that will store a list of six Lotto numbers and then invites the user to enter the latest set of Lotto numbers, including the Bonus number and checks how many matches there are for that draw.
------------------------------

I don't know how to compare two arrays which is what I think I've to do but I'm not even sure about that.. Any help would be appreciated. Thanks..
Feb 26 '07 #1
7 6504
sicarie
4,677 Expert Mod 4TB
K. I'm kinda totally lost on how to go about this....

Here's the Question:
------------------------------
Write a program that will store a list of six Lotto numbers and then invites the user to enter the latest set of Lotto numbers, including the Bonus number and checks how many matches there are for that draw.
------------------------------

I don't know how to compare two arrays which is what I think I've to do but I'm not even sure about that.. Any help would be appreciated. Thanks..
I think the first step would be to define how you are checking for the match. Do the numbers have to match in order, or can any number match (ie if 100000 is stored, will 999991 return the 1 as a match?) And what is the Bonus number - how is that handled?
Feb 26 '07 #2
I think the first step would be to define how you are checking for the match. Do the numbers have to match in order, or can any number match (ie if 100000 is stored, will 999991 return the 1 as a match?) And what is the Bonus number - how is that handled?
Well if the numbers 1 0 0 0 0 0 were the six winning numbers and 9 9 9 9 9 1 was the numbers on the ticket i would want the 1 to be counted.

The Six winning numbers I just want stored in an array or something. I want to be able to type 7 numbers to be checked including the bonus number. But is there a way for the bonus number to be kinda separate or something?? thanx.
Feb 26 '07 #3
RedSon
5,000 Expert 4TB
What happens if the user gets a lotto ticket that is 1 2 3 4 5 4 and the winning numbers in the drawing are 1 1 1 1 4 4. Then how many matches are there? Do you allow both the user lotto tickets and the winning lotto tickets to repeat??
Feb 26 '07 #4
sicarie
4,677 Expert Mod 4TB
Well if the numbers 1 0 0 0 0 0 were the six winning numbers and 9 9 9 9 9 1 was the numbers on the ticket i would want the 1 to be counted.

The Six winning numbers I just want stored in an array or something. I want to be able to type 7 numbers to be checked including the bonus number. But is there a way for the bonus number to be kinda separate or something?? thanx.
Yeah, definitely.

Ok, so now that you know how you want the numbers processed, you need to come up with an algorithm - a list of simple steps on how to create your result.
Feb 26 '07 #5
The six winning lotto numbers aren't going to change, so let's say they are 7, 4, 16, 21, 35, 33. They will stay the same. I don't want to generate winning lotto numbers or anything like that. But I want to type in 7 numbers to be checked against these numbers. I want the program to be able to count how many numbers match. I don't know how to compare two arrays simply. I've read about 'bool' and all this but I only want to use the iostream class or if not possible alone then two classes. Please help... Thanx
Feb 27 '07 #6
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #define MAX 6
  3. #define LOT 7
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int number[MAX];
  9.     int index,temp;
  10.     int winnumbers[LOT];
  11.     int match=0;
  12.  
  13. //gather data and put it in array    
  14.     for (index=0;index<MAX;index++)
  15.     {
  16.         cout<<"Please enter the six winning lotto numbers--->    ";
  17.         cin>>number[index];
  18. }
  19.  
  20. for (index=0;index<LOT;index++)
  21. {
  22.      cout<<"Please enter numbers to be checked for a win         ";
  23.      cin>>winnumbers[index];
  24.      }
  25.  
  26. for(int index=0;index<MAX;index++)
  27. {
  28.    for(int temp=0;temp<LOT;temp++)
  29.    {
  30.       if(number[index]==winnumbers[temp])
  31.       {
  32.         match++; //you have a match in array2 for a value in array 1, so break the inner loop
  33.  
  34.  
  35.  
  36.      cout<<"There are "<<match<<" matches between the two numbers."<<endl;
  37.  
  38.      }
  39.      else 
  40.      {
  41.      cout<<"";
  42.      }
  43. }
  44. }
  45.  
  46.     system("PAUSE");
  47.     return EXIT_SUCCESS;
  48.  
  49. }
  50.  
Please Help.. I wanna just display the number of matches... How??
Mar 5 '07 #7
lqdeffx
39
looks like you almost got it. the only problem i see is if you have lotto numbers: 1 2 3 4 1 6 and someone had picked 1 7 8 9 10 11 12, the program will see 2 matches. This is because your inner loop sets the index back to 0 each time the outer loop iterates. Correct me if i'm wrong but i think it is a 1:1 ratio between winning numbers and picked numbers. in any case if you throw in an offset and restructure the inner array: that would be one way to solve your problem.
Expand|Select|Wrap|Line Numbers
  1. ...
  2. int matches = 0;
  3. // lotto array
  4. for( int i = 0; i < 6; i++ )
  5. {
  6.    // picked array
  7.    for( int x = 0 + matches; x < 7; x++ )
  8.    {
  9.       if( lotto[i] == picked[x] )
  10.       {
  11.          int temp = 0;
  12.  
  13.          temp = picked[matches];
  14.          picked[matches] = picked[x];
  15.          picked[x] = temp;
  16.  
  17.          matches++;
  18.       }// end of if
  19.    }// end of inner for
  20. }// end of outer for
  21.  
  22. cout << "Congratulations! You have " << matches << " matches!\n";
  23. ...
  24. // exit code
  25.  
this should work, although i haven't tested it.
Mar 5 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jcs_5920 | last post by:
Hello All, I was reading some of the posts trying to learn about date coding schemes used in old DOS programs with no luck, so I though I'd ask the group for help. These are the HEX values and...
0
by: Calvin KD | last post by:
Hi everyone, I need help urgently. I have a C#.Net app which uses cookies for state management (since we've gone away from Session for fear of webfarm and we haven't found the need for SQL Server...
0
by: almurph | last post by:
Hi, Hope you can help me. This is a trick one - at least I think so. I have 2 strings. I have to calculate the "score" of the strings. Score is determined by matching patterns of letters within...
2
by: cpptutor2000 | last post by:
Could some PHP guru please help me? I have very standard PHP - MySQL application that reads in some data from a table and for each row, puts a check box at the start of the row. Now the check boxes...
1
by: marsguy85 | last post by:
a program that repeatedly request an integer from the user and displays the integer as a binary number. It should terminate when the value 9999 is entered. A typical run might look like: Enter...
2
by: Bsnpr8 | last post by:
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assignment is to do a spell checker in C++, i have an idea but nothing is coming out. I really...
1
by: ndawg123 | last post by:
Hey guys what im trying to do is write a yatzee game with C. And im stuck already and its the start?!?! I want the user to type there 5 numbers. i.e My program so far does this Please...
2
by: karmakiller | last post by:
Hi I have this code and it works well, but how do I add another check for valid.Surname ??? Please Help // Validator Object var valid = new Object(); // REGEX Elements
6
by: Simon Harvey | last post by:
Hi all, I'm really hoping someone can help me with this as it's causing me some serious problems. I have a Windows Forms application using the gridview control. When the user selects a row,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.