Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.71 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can my random number generator come up from lowest to highest in C  ? [closed]
  2. /*This app will give you your lotto max numbers!*/
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <cstdlib>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int lotto[7];
  11.     //allows users to input a seed, that way the tickets wont be
  12.     //generated the same if    they want two.
  13.     unsigned seed;
  14.     cout << "Enter seed ";
  15.     cin >> seed;
  16.     srand( seed ) ;
  17.  
  18.     //greeting
  19.     cout << "*** LOTTO  MAX  INSTA  PICK ***" << endl;
  20.     cout << " " << endl << endl;
  21.  
  22.     cout << "Your Insta Pick Numbers" << endl;
  23.     cout<< " " << endl << endl;
  24.  
  25.     //initilizes the counter and making sure the amount of numbers does not exceed 21
  26.     for (int counter = 1; counter <= 7;++ counter)
  27.     {
  28.         //outputs numbers between 1 and 27 with 7 numbers in each row
  29.         cout << setw(1) << (1 + rand() % 49)  << " " ;
  30.         //stops the counter for each row
  31.         if (counter % 7 == 0)
  32.             cout << endl;
  33.     }
  34.  
  35.     //space in between the numbers and tag numbers
  36.     cout<< " " << endl << endl;
  37.     cout << "Your Tag Numbers" << endl;
  38.     cout << " " << endl << endl;
  39.  
  40.     //initilizes counter and makes sure numbers dont go over 6
  41.     for (int counter = 1; counter <= 6; ++ counter)
  42.     {
  43.         //sets the numbers between 0 and 9 and outputs them
  44.         cout << setw(0) << (0 + rand() % 9)<< " " ;
  45.  
  46.         //stops the counter
  47.         if (counter % 9 == 0)
  48.             cout << endl;
  49.     }
  50.  
  51.     cout << " " << endl << endl;
  52.  
  53.     //end message
  54.     cout << "Thank you for playing!! please check ticketn a year minus a day   from date of purchase" <<endl;
  55. };
  56.        
  57. std::set<int> numbers;
  58. while(numbers.size() < 7)
  59. {
  60.     numbers.insert((rand() % 49) + 1);
  61. }