1. ## Simple programming help

Why are the last two equations printing the wrong numbers? Thanks in advance.

Code:
```#include <stdio.h>
#include <math.h>

int main() {

int x1,x2,x3,y1,y2,y3;
float c12,c13,c14;

printf("What are the first x and y coordinates?\n");
scanf("%d %d", &x1, &y1);
printf("What are the second x and y coordinates?\n");
scanf("%d %d", &x2, &y2);
printf("What are the third x and y coordinates?\n");
scanf("%d %d", &x3, y3);

c12 = (pow(x2 - x1,2) + pow(y2 - y1,2));
c12 = sqrt(c12);
printf("%.2f\n", c12);
c12 = (pow(x3 - x1,2) + pow(y3 - y1,2));
c12 = sqrt(c13);
printf("%.2f\n", c13);
c12 = (pow(x3 - x2,2) + pow(y3 - y2,2));
c12 = sqrt(c14);
printf("%.2f\n", c14);

return 0;

}``` 2. What's the value of c13 and the value of c14 prior to you passing them to sqrt? That's why.

Also, for future reference, "wrong number" doesn't tell me anything. Try providing sample input, expected output, and actual output. It'll save us all time.

Quzah. 3. I fixed that problem and the output is still incorrect. For c12 I get the correct answer but for c13 and c14 I am getting 1627902208.00.

Code:
```#include <stdio.h>
#include <math.h>

int main() {

int x1,x2,x3,y1,y2,y3;
float c12,c13,c14;

printf("What are the first x and y coordinates?\n");
scanf("%d %d", &x1, &y1);
printf("What are the second x and y coordinates?\n");
scanf("%d %d", &x2, &y2);
printf("What are the third x and y coordinates?\n");
scanf("%d %d", &x3, y3);

c12 = (pow(x2 - x1,2) + pow(y2 - y1,2));
c12 = sqrt(c12);
printf("%.2f\n", c12);
c13 = (pow(x3 - x1,2) + pow(y3 - y1,2));
c13 = sqrt(c13);
printf("%.2f\n", c13);
c14 = (pow(x3 - x2,2) + pow(y3 - y2,2));
c14 = sqrt(c14);
printf("%.2f\n", c14);

return 0;

}``` 4. > scanf("%d %d", &x3, y3);
You forgot the & for y3
Which compiler are you using? 5. Thanks for catching that. I am using Jgrasp with GCC. 6. Then set it up to compile with
gcc -W -Wall -ansi -pedantic -O2 prog.c

That will catch (along with lots of other stuff) the problem of getting the parameters to printf and scanf mixed up. Popular pages Recent additions 