Good afternoon fellow coders. I'm working on a program that draws a square at a random location. Everything works fine and the square is drawn, but the only problem is that it isn't drawn at a random location. Can anyone help?
#include "DarkGDK.h"
//prototypes
void randSqe(int& x1, int& x2,int& y1, int& y2);
void getGuees(int& x, int& y);
void drawCircle(int x, int y);
void test(int x, int y, int x1, int x2, int y1, int y2);
void drawbox(int x1, int x2, int y1, int y2);
//main function
void DarkGDK(){
//initializes parameters
int a,b,c,d,e,f;
//function calls
randSqe(a,c,b,d);
getGuees(e,f);
drawCircle(e,f);
test(e,f,a,c,b,d);
//Ends Program
dbWaitKey();
}
//function draws random squar
void randSqe(int& x1, int& x2,int& y1, int& y2){
x1 = dbRND(640);
x2 = x1+50;
y1 = dbRND(480);
y2 = y1+50;
dbBox(x1,y1,x2,y2);
}
//This function draws the box with the random coordinates
void drawbox(int x1, int x2, int y1, int y2){
dbBox(x1,y1,x2,y2);
dbPrint(dbStr(x1));
dbPrint(dbStr(y1));
}
//This function prompts user to take a guess at the coordinates of the square
void getGuees(int& x, int& y){
dbPrint("Take a guest on where the box is");
dbPrint("Pick a x point in the square");
x = atoi(dbInput());
dbPrint("Pick a y point in the square");
y = atoi(dbInput());
}
//This function draws a cir a circle at the user's guess
void drawCircle(int x, int y){
int radius = 25;
dbCircle(x,y,radius);
}
// This function test coordinates.
//IF the guess is wrong it will start over telling the user to try again
//If the guess is correct it will congratulate the user
void test(int x, int y, int x1, int x2, int y1, int y2){
//initializes test variables
int test1=x1+25;
int test2=y1+25;
//This while loop keeps going until the guess is correct
while(x!=test1 && y!=test2){
if(x==test1 && y==test2)
dbPrint("");
else{
dbPrint("TRY AGAIN???");
getGuees(x,y);
drawCircle(x,y);
test(x,y,x1,x2,y1,y2);
}
}
dbPrint("CONGRATULATIONS");
}