Advertisement
KeeganT

Ass64

Oct 15th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     srand(time(NULL));
  10.     int array[40];
  11.     int num, val;
  12.     bool found=false;
  13.     for(int c=0;c<40;c++)
  14.     {
  15.         val=rand()%40+1;
  16.         for(int x=0;x<40;x++)if(val==array[x])found=true;
  17.         if(found==false)array[c]=val;
  18.         else c--;
  19.         found=false;
  20.     }
  21.     cout<<"Give an amount of numbers to be generated (Between 1 and 20) ";
  22.     cin>>num;
  23.     while(num>20||num==0)
  24.     {
  25.         cout<<"Invalid number, please choose a number between 1 and 20 ";
  26.         cin>>num;
  27.     }
  28.     for(int c=0;c<num;c++)cout<<array[c]<<", ";
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement