|
Following is instructions for a small program that I have to write for school but I can't get mine to work properly. I would be forever grateful to someone if they could help me out. Here are the instructions:
5 individuals have bought lottery tickets in SCs new pick 6 lottery.
Have each person enter her name and her six numbers (the numbers
must be between 1 and 48, and there should be no duplicate values).
After all of the names and tickets are entered, populate (fill) a 6
element array with 6 randomly generated numbers (no duplicates!).
If a user picked 4 of the numbers correctly - she wins $1000.
If a user picked 5 of the actual numbers - she wins $10000.
If a user picked all 6 numbers correctly - she wins $1000000.
Note, the order of the numbers does not matter.
Print out the names of each winner and the amount of money
she won.
Your program must use AT LEAST two functions in addition to your
main (write more if you would like):
1. Write a function that takes an array and a size as its parameters.
This function should fill the array with random numbers between 1
and 48 - ensuring that there are no duplicates.
2. Write a linear search function.
Here is a suggested plan of attack:
1. Make your program read in one person's name and lottery picks
(into an character array with one row and 20 columns and a one
dimensional integer array with 6 columns).
2. Make sure that the user's numbers are in range and are not duplicates.
Do this as the numbers are being read in. - YOU CAN SKIP THIS
STEP AND COME BACK TO IT AT THE END IF YOU WANT
3. Write a function that takes an integer array as its parameter and
fills the array with 6 random numbers between 1 and 48.
4. Make sure the function written in step 3 is not allowed to place
duplicate values in the array. (You may want to reduce the number
of possible values to 1-6 in order to test that this feature is working)
- YOU CAN SKIP THIS STEP AND COME BACK TO IT AT THE
END IF YOU WANT
5. Print the elements in the array of randomly generated values.
6. Search the array of randomly generated values for each of the user's
numbers. Keep a count of the number of values found.
7. Construct a decision structure that will print the user's name and
winnings if she won.
8. Go back and make steps 1 and 2 read in 5 names and sets of
lottery picks.
9. Go back and make steps 6 and 7 check the picks for each of
the 5 people.
Donna
|
|
|
|
|
I'd follow the plan of attack outlined in your post. It seems pretty helpful.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I did follow the instructions, but my instructor told me that although my program looks like it works, my array is full of junk!
|
|
|
|
|
Donna wrote:
my array is full of junk!
Post some sample code ... we can't really help you... and I don't really
think we'll provide ( at least I ) you with a fully coded solution...
Max.
|
|
|
|
|
As you will see, I am extremely new at this but here is what I have so far:
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <time.h>
void lotteryNbr(int[], const int);
int linearSearch(int[], int, const int);
int main(){
char names [20];
const int sizeOfArray = 6;
int num[6],a[sizeOfArray],element;
cout <<"Please enter your first name " << endl;
cin >> names;
cout <<"Hi, "<< names << "!" <<" What numbers did you pick for";
cout <<" this weekends lottery drawing?" << endl;
cout <<"(6 integers between 1 and 48, no duplicates!)"<< endl;
for (int i = 0; i < 6; ++i){
cin >> num[i];
}
lotteryNbr(a,sizeOfArray);
element = linearSearch(a, num[i], sizeOfArray);
if (element != -1)
cout << "You have won the lottery!" << endl;
else
cout << "Sorry you didn't match any numbers." << endl;
return 0;
}
void lotteryNbr(int gameNbr[], const int arraySize)
{
cout << "This weeks lottery numbers are " << endl;
srand(time(0));
for (int j = 0; j < 6; ++j){
gameNbr[j]=(1 + rand() % 6);
cout << gameNbr[j]<< endl;
}
}
int linearSearch(int array[], int key, const int arrayLength)
{
for (int n = 0; n < arrayLength; ++n)
if (array[n] == key)
return n;
return -1;
}
|
|
|
|
|
I think you're missing a couple of includes ...
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <time.h>
using namespace std;
1- Should try to validate each user input so that it's between 1 to 48 ...
2- The random generator only generates numbers up to 6 ( get it, up to 6 that's
a hint )
3- To check whether you've win or lost, you need to check each number of array "a"
with each number of array "num", now, you are only checking the last number of
num ( which by chance works ) because "i" luckily "5" because of the loop;
this function should either do everything ( with the 2 arrays as parameters ),
or with one user number and the picked number array and return true/false to
say whether the user picked a good number, and in that case, will increment a
counter that will enable you to do the "decision structure' ( a big if statement
or a case statement ).
4- you're on the way ...
Good luck.
Max.
|
|
|
|
|
Damn, I can't put the include brackets ... that's why I didn't see yours...
Max.
|
|
|
|
|
You need to check 'display message as is' to stop the < > from being stripped as HTML tags. Or you can use & and lt or gt to get them, as I did here.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
You need to check 'Display this message as-s (no HTML)' below if you're going to have #includes in < and >.
Donna wrote:
gameNbr[j]=(1 + rand() % 6);
This line is going to generate numbers between 1 and 6. Is this what you want ? Also, I see no checking for duplicates.
I also don't get how your linear search works. I think you want to step through your numbers, and call linear search on each of them, and count how many you find. As it stands, I don't see how it could work.
I also don't see a using statement anywhere - you're not including iostream.h, are you ? You need to include iostream instead, which means you need a using statement for namespace std or, preferably, for each element you use, in this case only cin and cout.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Or you may use the code & # 0 6 0 for <, and & # 0 6 2 for >.
that's a bit like ASCII code...
Maxwell Chen
No code is good code.
|
|
|
|
|
My header files did not print to the screen like I had them in my program! The greater than and less than signs and what's in between them does not show up on the message board! The header files were iostream.h, iomanip.h, stlib.h, and time.h.
|
|
|
|
|
I explained to you why that is above, and also explained why including iostream.h, iomanip.h, etc. is plain wrong.
I don't use C functions, because I prefer C++, but I believe that stdlib.h and time.h are also deprecated, in favour of cstdlib.h and ctime.h.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Do you know the escape sequence in C/C++. For example: \0, \n, \a, \r, \t, \\, or %%, etc. ??
HTML has such thing, too! Now follow my step-by-step...
1) Open(create) a new file with the notepad.exe.
2) Type such things
&*#*0*6*0*S*T*D*I*O*.*H*&*#*0*6*2*
3) Save this document in a name, like "WebDoc.txt". Do not close this document.
4) Use the replace tool (Ctrl+H), replace all the * with nothing (Not ask you to put a lot this word 'nothing's, just delete all * symbols.)
5) Save this document again, close it, and rename it as WebDoc.htm.
6) You see the icon of the file becomes a web document.
7) Open this document with your browser (IE or some other one...).
8) You now see this:
<STDIO.H>
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Hi,
I have a DDE server running on a Windows 98 plattform.
A DDE client , executed by IIS (internet Information Server), communictes with it and everything is OK. Both, client and server uses ddeml. When I try to do the same on WinNT or Windows 2000 I have the following problem: the DDE client , executed by IIS, attempts to communicate with the DDE server but, the server never receives the message. But, when I run the DDE client from the shell (on NT or 2000), again, everything is right. The client sends the message and the server receives it. The DDEspy reports DDE activities when the client is executed from shell, but when it is called for the IIS, DDEspy doesnt report DDE activity.
Could anybody help me?
Valeria león
|
|
|
|
|
Probably a security problem. The client and the server are probably running on different desktops and thus don't see each other.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi,
Both applications: DDE client and DDE server are running in https/cgi-win. If they are in different desktops, how can I solve this? On Windows 2000, my system file is FAT.
TANK YOU.
Valeria León
|
|
|
|
|
I have created this dialog based application consisting of several pages (property pages) and I would like to load a bitmap that I created. I want this bitmap to be displayed on the 1st page.
thank you very much! = )
|
|
|
|
|
The basic way is to use LoadImage (which accepts a file path) to get a handle to the bitmap, then SetBitmap of CStatic control to display it. You need to make sure that the size of your static is equal or more than the size of the bitmap loaded, otherwise it won't be displayed
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
Does anybody know of how to completely turn off the task list thing in VC++.NET? I thought I had set all the VC 6 compatibility, but everytime I hit F4 in the output window it opens the task list.
TIA!
|
|
|
|
|
Tools->Options->Environment->Keyboard
If you select the VC6 scheme, set focus to the Press shortcut keys edit control and click the F4 key, you'll see that in that scheme, it resolves to a the View Next Task command. Simply change it to whatever you want
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Hi,
I'm playing with an FTP client, and I'm trying to figure out how to download files from the server in PASSIVE mode. The problem is, I can't figure out how to tell when the client should stop trying to recv data from the data socket and close the socket. In normal mode, the server would close the socket, so I could simply recv until I got a CLOSE event on the socket, then just read the remaining queued data.
So, how do I tell when a transfer is finshed in PASV mode? I was originally thinking that I could wait for the 226 - Transfer OK on the control socket, and then stop when got that, but that seems to arrive before all of the data has arrived on the data socket, so it's not very reliable. Should I just count the number of bytes received and compare to the file size indicated by the server?
Thanks
|
|
|
|
|
I wrote a Pro*C application in VC++ on Windows 2000 and I built it and it runs fine on my machine, but when I try to execute it on the server running NT, it doesn't execute. Not sure if I'm building it wrong or anything like that. I've never had this problem before.
Does anyone have any ideas?
|
|
|
|
|
You might be using some features not availiable on NT4, there's plenty of stuff that works on Win2k that doesn't work on NT4...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi,
Is there any function that converts one string into a valid XML tag ? ( In my app the user types some names for some values, then I want to use that names as tag names but I would like to filter them to avoid having a bad formed XML file).
Thanks, Bye !
Braulio
|
|
|
|
|
If you are using IXMLDOMDocument, if I remember it correctly, it's all taken care of for you.
Are you maybe just looking for a general escape function?
|
|
|
|
|