I now have another problem, this is my current update on my code below.
When the user enters six integers it should print out the twoboxes result, the combination of the two bounding boxes of the circles. instead it prints the first x1,y1 coordinates correctly but the x2,y2 coordinates are miles out.
I think this is something to do with the inputting of the data as it worked before I added this step. I am not sure entirely how to encode this to read the integers in properly.
Code:
#include <stdio.h>
typedef struct{
int x,y;
int r;
}circle;
typedef struct{
int x1,y1;
int x2,y2;
}boundingbox;
circle makecircle(int x, int y, int r)
{
circle temp;
temp.x = x;
temp.y = y;
temp.r = r;
return temp;
}
boundingbox bounding_box(circle circ)
{
int xa,xb,ya,yb;
xa = circ.x - circ.r;
ya = circ.y - circ.r;
xb = circ.x + circ.r;
yb = circ.y + circ.r;
boundingbox temp1;
temp1.x1 = xa;
temp1.y1 = ya;
temp1.x2 = xb;
temp1.y2 = yb;
return temp1;
}
boundingbox twoboxes(boundingbox bound, boundingbox bound1)
{
boundingbox combination;
if (bound.x1 < bound1.x1){
combination.x1 = bound.x1;}
else {
combination.x1 = bound1.x1;}
if (bound.y1 < bound1.y1){
combination.y1 = bound.y1;}
else {
combination.y1 = bound1.y1;}
if (bound.x2 > bound1.x2){
combination.x2 = bound.x2;}
else {
combination.x2 = bound1.x2;}
if (bound.y2 > bound1.y2){
combination.y2 = bound.y2;}
else {
combination.y2 = bound1.y2;}
return combination;
}
int printboundbox(boundingbox bound)
{
printf("(%d", bound.x1);
printf(",%d", bound.y1);
printf(") ");
printf("(%d", bound.x2);
printf(",%d", bound.y2);
printf(")\n");
return 0;
}
int main()
{
circle circ;
circle circ1;
boundingbox bound;
boundingbox bound1;
boundingbox combination;
char userdata[10];
printf("Please enter the co-ordinates and then radii of two cirles in turn: ");
scanf("%s", userdata);
circ = makecircle(userdata[0],userdata[1],userdata[2]);
bound = bounding_box(circ);
circ1 = makecircle(userdata[3],userdata[4],userdata[5]);
bound1 = bounding_box(circ1);
combination = twoboxes(bound,bound1);
printboundbox(combination);
return 0;
}