Help me find the error

//to find the distance between two coordinate(consecutive points distance sum)

#include<stdio.h>

#include<math.h>

int main()

{

int x[10], y[10], i,r1,r2;

float z[10],d;

printf("enter the  x and y corrdinate \n");

for(i=0;i<=9;i++);

{

    scanf("%d",&x[i]);

    scanf("%d",&y[i]);

}

for(i=0;i<=8;i++)

{

r1=pow((x[i+1]-x[i]),2);

r2=pow((y[i+1]-y[i]),2);

z[i]=sqrt(r1+r2);

}

for(i=0;i<=8;i++)

{

d=0;

d=d+z[i];

}

printf(“the distance is %d”,d);

return 0;

}

Please find a Post-It™ Note and write “check for semi-colons at the end of for loops” and stick it to your monitor - this is ( least) the third time you’ve made this mistake :slight_smile:

Edit:

gcc even warns you about it:

Compiling negia-blah.cpp
Executing command:
  g++ -std=c++17 negia-blah.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
negia-blah.cpp: In function ‘int main()’:
negia-blah.cpp:15:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
     for(i=0;i<=9;i++);
     ^~~
negia-blah.cpp:17:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
     {
     ^
negia-blah.cpp:29:15: warning: conversion to ‘int’ from ‘__gnu_cxx::__promote_2<int, int, double, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
         r1=pow((x[i+1]-x[i]),2);
            ~~~^~~~~~~~~~~~~~~~~
negia-blah.cpp:31:15: warning: conversion to ‘int’ from ‘__gnu_cxx::__promote_2<int, int, double, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
         r2=pow((y[i+1]-y[i]),2);
            ~~~^~~~~~~~~~~~~~~~~
negia-blah.cpp:33:18: warning: conversion to ‘float’ from ‘__gnu_cxx::__enable_if<true, double>::__type {aka double}’ may alter its value [-Wfloat-conversion]
         z[i]=sqrt(r1+r2);
              ~~~~^~~~~~~
negia-blah.cpp:47:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
     printf("the distance is %d",d);
                                  ^
negia-blah.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x[i]);
         ~~~~~^~~~~~~~~~~~
negia-blah.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&y[i]);
         ~~~~~^~~~~~~~~~~~
Successful
3 Likes

#include <stdio.h>
#include <math.h>

int main()

{

int x[4], y[4], i, r1, r2;

int z[4], d = 0;

printf("enter the  x and y corrdinate \n");

for (i = 0; i <= 3; i++)

{

    scanf("%d", &x[i]);

    scanf("%d", &y[i]);

}

for (i = 0; i <= 2; i++)

{

    r1 = pow((x[i + 1] - x[i]), 2);

    printf("the r1 is % d\n", r1);

    r2 = pow((y[i + 1] - y[i]), 2);

    printf("the r2 is % d\n", r2);

    int p = r1 + r2;

    z[i] = sqrt(p);

}

for (i = 0; i <= 2; i++)

{  

    d = d + z[i];

}

printf("the distance is % d", d);

return 0;

}

This post was flagged by the community and is temporarily hidden.