View Single Post
Join Date: Nov 2008
Posts: 8
Reputation: techgenie is an unknown quantity at this point 
Solved Threads: 0
techgenie techgenie is offline Offline
Newbie Poster

Generate 6 Random Numbers

 
0
  #1
Nov 14th, 2008
Hi guys
I am working on a Lottery program to generate 6 unique numbers. So far I have the following:

CLASS LOOKS LIKE THIS:
  1. #include "stdafx.h"
  2. #include <string>
  3. #include <ctime>
  4. #pragma once
  5. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  6.  
  7. class Lottery // Lottery class definition
  8. {
  9. public:
  10. Lottery(); // constructor that initializes a Lottery object
  11. void setLottery(int []); // function that gets lottery numbers
  12. int getLottery(); // function that retrieve the lottery numbers
  13. bool checkLottery(int, int []); // function that evaluates the lottery numbers
  14. void displayLottery(int []); // function that displays the lottery numbers
  15.  
  16. private:
  17. int lotNumbers[6]; // lottery number
  18. }; // end of class Lottery
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7.  
  8. #include <string>
  9. #include <ctime>
  10. using std::string;
  11.  
  12. #include "lottery.h" // include definition of class lottery
  13.  
  14. // constructor for the Lottery
  15. Lottery::Lottery()
  16. {
  17.  
  18. } // end of Lottery constructor
  19.  
  20. bool Lottery::checkLottery(int lotnum, int lottery_numbers[6])
  21. {
  22. for (int i=0; i < 6; i++)
  23. {
  24. if (lottery_numbers[i] == lotnum || lottery_numbers[i] == 0)
  25. {
  26. return false;
  27. }
  28. }
  29. return true;
  30. }
  31. void Lottery::setLottery(int lottery_numbers[6])
  32. {
  33. lotNumbers[6] = lottery_numbers[6];
  34. }
  35.  
  36. int Lottery::getLottery()
  37. {
  38. return lotNumbers[6];
  39. int lot_count = 0; // counter for the number of valid lottery numbers found
  40. while (lot_count < 6)
  41. {
  42. time_t = t;
  43. srand(unsigned (time(&t)));
  44. int lotnum = (rand() * 53);
  45. if (checkLottery(lotnum, lotnumbers))
  46. {
  47. lotnumbers[lot_count] = lotnum;
  48. lot_count++;
  49. }
  50. }
  51. }
  52.  
  53. void Lottery::displayLottery()
  54. {
  55. getLottery();
  56. for (int j = 0; j < 6; j++)
  57. {
  58. cout << getLottery() << " ";
  59. }
  60. getche();
  61. }
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. #include <string>
  8. #include <ctime>
  9.  
  10. #include "lottery.h" // iinclude definition of class lottery
  11.  
  12. // function main begins program execution
  13.  
  14. int main()
  15. {
  16. int lottery_numbers[6];
  17.  
  18. Lottery lotteryDraw; //create Lottery object
  19.  
  20. lotteryDraw.displayLottery();
  21.  
  22. return 0; // indicate successful termination
  23.  
  24. } // end main function
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

===============
Last edited by Narue; Nov 14th, 2008 at 12:09 pm. Reason: added code tags
Reply With Quote