d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > ~* Iso Some Programming Help *~ > I Can Pay Fg If U Are Interested.
Closed New Topic New Poll
Member
Posts: 9,330
Joined: Oct 2 2006
Gold: 0.00
Sep 25 2013 02:01pm
I have plenty fg if u want any for helping.
This is a programming in C class

This is my assignment
Description:

Create a C program that reads in a stream of integer pairs,
each representing an (x,y) pair in the cartesian coordinate
system. For each successive pair of integers, display the
distance and direction traveled from one pair to the next.

You can assume that in each successive pair only one value
changes, so that travel is always right, left, up, or down.

{This would be like the locations displayed in the tracker.c
example from the "Conditional Statements" section in
Polzin's online notes (the x, y values.) }

Also, keep a running total of the distance between each pair
of points and determine the distance between the
initial/starting point and the final/finish point.

This is what I got so far.


#include <stdio.h>
#include <stdlib.h>
int main ()
{
int x, y;
int b=2;
int a;
printf(" How many different Coordinates: ");
scanf("%d",&a);
int array[a][b];
for(y = 0; y <= a-1; y++)
{
printf("Enter points: ");
for(x = 0; x <= b-1; x++)
scanf("%d", &array[x][y]);
}
printf("\n");
for(x = 0; x <= b-1; x++)
{
for(y = 0; y <= a-1; y++)
printf("[%d][%d]=%2d ", x, y, array[x][y]); //Just to show what the array is holding.
printf("\n");
}

So basically I have the array but now how do I use the array to calculate the distance between points and keep a running total??



Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Sep 25 2013 02:29pm
make a for loop to iterate through the array.
in each iteration you calculate the x-difference and the y-difference.
if x and y-difference are both different from zero, then the distance does not go in only 1 direction, thus don't sum up that distance
if x or y difference is zero, add x and y to the sum of the distance (make sure you take the abs() value)
make a variable that holds the total distance so far (initialize it with zero)

Code
int totaldistancesofar = 0;

then in each step you do:
if (x == 0 || y== 0)
totaldistancesofar += abs(x+y);
Go Back To Programming & Development Topic List
Closed New Topic New Poll