![]() |
| ||
| Generate 6 Random Numbers Hi guys I am working on a Lottery program to generate 6 unique numbers. So far I have the following: CLASS LOOKS LIKE THIS: #include "stdafx.h" #include "stdafx.h" #include "stdafx.h"I am getting the following errors and I do not understand where to go from here. wrig_9.cpp c:\users\jeannie\documents\visual studio 2005\projects\wrig_9\wrig_9\wrig_9.cpp(25) : error C2660: 'Lottery::displayLottery' : function does not take 0 arguments lottery.cpp c:\users\jeannie\documents\visual studio 2005\projects\wrig_9\wrig_9\lottery.cpp(47) : error C2513: '__time64_t' : no variable declared before '=' c:\users\jeannie\documents\visual studio 2005\projects\wrig_9\wrig_9\lottery.cpp(47) : error C2065: 't' : undeclared identifier c:\users\jeannie\documents\visual studio 2005\projects\wrig_9\wrig_9\lottery.cpp(48) : fatal error C1903: unable to recover from previous error(s); stopping compilation Generating Code... Build log was saved at "file://c:\Users\Jeannie\Documents\Visual Studio 2005\Projects\wrig_9\wrig_9\Debug\BuildLog.htm" wrig_9 - 4 error(s), 0 warning(s) ==================================== I think the arrays are not declared properly and the calls are inaccurate. Any help is appreciated. Please let me know what I am doing wrong. Thanks so much techgenie =============== |
| ||
| Re: Generate 6 Random Numbers >error C2660: 'Lottery::displayLottery' : function does not take 0 arguments >void displayLottery(int []); Looks like it takes one argument to me. You can't lie to your compiler, it doesn't work. >error C2513: '__time64_t' : no variable declared before '=' >time_t = t; Yep, this error is pretty straightforward too. You need to name your variables. |
| ||
| Re: Generate 6 Random Numbers Why are you passing an array to displayLottery (in the declaration), it's not used in the method? Also, when you set the lottery you are only setting index # 6. And if you had properly passed your array from main it would be an out of range index (which will throw an exception). Also, when you generate random numbers, use a mod (%) operator, not a * operator. I may be wrong, but I think it's possible for this to generate a int so big that it's bigger than an int's range. rand() % (MAX + 1)will generate a number between 0 and MAX, inclusive. |
| ||
| Re: Generate 6 Random Numbers Thank you skatamatic for that suggestion on the modulus (%). Narue I realized I had omitted the <ctime> and <cstdlib> libraries. After adding them it made it easier for me to identify the other errors. As the program stands right now; it has finally compiled but I do not get random numbers between 1 and 53, as it should. I am getting an extremely large number out of range (- 858993460). I get 6 of the same numbers. Any suggestions? The modified function definitions are: #include "stdafx.h" |
| ||
| Re: Generate 6 Random Numbers Adding code tags to other people's posts gets old very quickly. Please start using code tags when you post code. |
| ||
| Re: Generate 6 Random Numbers using std::cout; Hope this helps! |
| ||
| Re: Generate 6 Random Numbers Why are you returning the 6th lottery number (again, out of range) in getLottery()? You are using arrays incorrectly. Each entry in the array needs to be accessed seperately. And what's with this line? lottery_numbers[i] = i * i; //store lottery numbers in the??? This program is pretty erronous and confusing. Fix up your syntax issues with your class methods, array passing, and loop techniques. Use google for syntax issues. |
| ||
| Re: Generate 6 Random Numbers I have been working on this program for quite some time and I have gotten it to compile and execute but I am getting a Debug error - Runtime Check Failure #2 Stack around the variable 'fllottery_numbers was corrupted. the only function that has 'fllottery_numbers is the function below. Can anyone help with resolving this issue. Thanks for your time and patience. void Lottery::displayLottery() |
| ||
| Re: Generate 6 Random Numbers What is flLotterDraw doing? It's not in the previous code. Whatever it's doing, it's corrupting your array. Post that function. |
| All times are GMT -4. The time now is 9:33 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC