1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int checker (int,int,int,int,int,int,int,int,int);
int main()
{
int test[9];
int h;
srand (time(0));
int f =2;
for (int y=0; y<=9; y++){ //generates 9 random numbers
h= 1+(rand()%9);
test[y] = h;
}
int bbc =20;
while(bbc == 20){ // stops while loop when unique random 9 integers found because bbc doesn't equal 20 if check returns 42 (which means it is unique)
int z =1;
while (z==1){
for(int x=0;x<=8;x++){
if (test[x+1]<test[x]){ // moves every integer which is smaller than the integer on it's left to the left of that integer
int temp = test[x];
test [x] = test[x+1];
test [x+1] = temp;
}
}
if (test[1] >= test[0] && test[2] >= test[1] && test[3] >= test[2] && test[4] >= test[3] && test [5] >= test[4] && test [6] >= test[5] && test[7] >= test[6] && test[8] >= test[7]){ //ends while loop when integers in order
z=2;
}
}
bbc =checker (test [0],test[1],test [2],test [3],test [4],test [5],test [6],test [7], test [8]);
}
cout << "hello"; // outputs 'hello' when unique random number found.
}
int checker (int a, int b, int c, int d, int e, int f, int g, int h, int i){
int u;
if (a<b && b<c && c<d && d<e && e<f && f<g && h<i){ //checks to see if ordered array of integers unique
u =42; // if unique then u =42
}
else {
u =20; //else = 20;
}
return u; // returns value to checker function
}
|