Nostradonis
Nostradonis

Reputation: 55

Trying to calculate the distance between 2 points

/*----------------------------------------------------------------------------*/
/* Program Chapter 2 Modify                        */
/*                                                 */
/* This program calculates the                     */
/* distance between two points                     */

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

int main(void)
{
/* Declaration and initialization of variables.*/
double x1=1, y1=5, x2=4, y2=7, side_1, side_2, distance;

/* Compute the sides of a right triangle.      */
side_1 = x2 - x1;
side_2 = y2 - y1;
distance = sqrt(side_1*side_1 + side_2*side_2);

/* Print results.                              */
printf("The distance between the two points is ""%5.2f \n", distance);

/* Exit program.                               */
return 0;
}
/*----------------------------------------------------------------------------*/

I'm trying to get it to output "The distance between the two points is 3.61" in C via Visual Studio 2010 and it isn't working. This is my first time writing a C program. Any help is much appreciated.

Upvotes: 0

Views: 2295

Answers (1)

Phonon
Phonon

Reputation: 12727

You have an error in this line. It should be

printf("The distance between the two points is %5.2f \n", distance);

Notice that you had two double-quotes in there.

Upvotes: 1

Related Questions