Guest User

Untitled

a guest
Oct 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. char* myStr[]=
  8. {
  9. "The one string",
  10. "The two string",
  11. "The three string",
  12. "The four string",
  13. "The five string",
  14. "The six string",
  15. "The seven string",
  16. "The eight string",
  17. "The nine string",
  18. "The ten string"
  19. };
  20.  
  21. int usedNums[]={11,11,11,11,11,11,11,11,11,11}; //Numbers which have been used
  22.  
  23. bool checkArray(int n); //Returns true if n is not in usedNums
  24.  
  25. int main ()
  26. {
  27. srand (time(NULL)); //Seed the rng
  28.  
  29. int tmp; //random integer
  30.  
  31. for (int i=0;i<10;)
  32. {
  33. tmp=rand()%10; //Set tmp to a ranndom value
  34. if(checkArray(tmp)) //If the number of the string hasn't been used
  35. {
  36. cout << myStr[tmp] << endl;; //Cout the string
  37. usedNums[i]=tmp; //Add the number to what's been used
  38. i++; //Move forth
  39. continue;
  40. } else {
  41. tmp=rand()%10; //Get a new number
  42. continue;
  43. }
  44. }
  45.  
  46. cin.get(); //Wait to end
  47. return 0;
  48. }
  49.  
  50. bool checkArray(int n)
  51. {
  52. for (int j=0;j<10;j++)
  53. {
  54. if(usedNums[j]==n) //If a number n is in usedNums[], return false
  55. return false;
  56. continue;
  57. }
  58. return true; //Else returntrue
  59. }
Add Comment
Please, Sign In to add comment