-5

I want to write a code in which i want to know how much time is needed to move from one point to another.

Input

1) First line(input) is showing the maximum time required to reach

2) Second line(second and third input) shows the intial position.

3)Third line(fourth and fifth input) shows the final position.

4)fourth line shows the time taken to travel one step in left , right , up and down .

Output an integer denoting the time needs to reach, if not able to reach in time output a string Valar Codulis. Output the answer of each testcase on newline.

But my program is not running like this . why?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int c, d, e, f, b;
    scanf("%d", &b);
    printf("\n");
    scanf("%d", &c);
    scanf("%d", &d);
    printf("\n");
    scanf("%d", &e);
    scanf("%d", &f);
    printf("\n");
    int g, h, i, j;
    scanf("%d", &g);
    scanf("%d", &h);
    scanf("%d", &i);
    scanf("%d", &j);

    int k, l, m, n, o;
    e - c == k;
    f - d == l;
    if (e - c >= 0, f - d >= 0)
    {
        m = k*h;
        n = l*i;
    }
    else if (e - c <= 0, f - d >= 0)
    {
        m = k*g;
        n = l*i;
    }
    else if (k >= 0, l <= 0)
    {
        m = k*h;
        n = l*j;
    }
    else
    {
        m = k*g;
        n = l*j;
    }
    o = m + n;
    if (b >= o)
    {
        printf("\n %d", o);
    }
    else
    {
        printf("Valar Codulis");
    }
}

NOTE:I am a beginner.

EstevaoLuis
  • 2,422
  • 7
  • 33
  • 40
Koolman
  • 127
  • 1
  • 8

1 Answers1

2
e - c == k;

This line of code has no effect. It checks whether the value of e - c is equal to that of k but nothing is done with the result of the check.

If you want to assign a value to k, use k = e - c. Likewise with l = f - d.

if (e - c >= 0, f - d >= 0) should be if (e - c >= 0 && f - d >= 0). Multiple conditions for an if statement cannot be joined using a comma. The logical operator && means 'and'.

Anastasia
  • 712
  • 1
  • 5
  • 11