Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- char* myStr[]=
- {
- "The one string",
- "The two string",
- "The three string",
- "The four string",
- "The five string",
- "The six string",
- "The seven string",
- "The eight string",
- "The nine string",
- "The ten string"
- };
- int usedNums[]={11,11,11,11,11,11,11,11,11,11}; //Numbers which have been used
- bool checkArray(int n); //Returns true if n is not in usedNums
- int main ()
- {
- srand (time(NULL)); //Seed the rng
- int tmp; //random integer
- for (int i=0;i<10;)
- {
- tmp=rand()%10; //Set tmp to a ranndom value
- if(checkArray(tmp)) //If the number of the string hasn't been used
- {
- cout << myStr[tmp] << endl;; //Cout the string
- usedNums[i]=tmp; //Add the number to what's been used
- i++; //Move forth
- continue;
- } else {
- tmp=rand()%10; //Get a new number
- continue;
- }
- }
- cin.get(); //Wait to end
- return 0;
- }
- bool checkArray(int n)
- {
- for (int j=0;j<10;j++)
- {
- if(usedNums[j]==n) //If a number n is in usedNums[], return false
- return false;
- continue;
- }
- return true; //Else returntrue
- }
Add Comment
Please, Sign In to add comment