Hi, I was assigned a project using Microsoft visual, and its my first time using it so I need some help. I was asked to write a program that converts kilometers to miles, while displaying it.
Heres what I have so far..I think its right, but when I try to run the program it exits right after i type in the Km value and hit enter, it doesnt show the results in miles.. anybody know why?
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
int main()
{
/* Declare and initialize variables. */
double km, miles;
/* get the km and mi values from the keyboard*/
printf("Enter distance in kilometers:");
scanf("%lf",%26amp;km);
/* Compute Kilometers to Miles */
miles=km/1.6093340;
/*print Miles */
printf("Kilometers = %f \n", km);
printf("Miles = %f \n", miles);
}
Microsoft visual c++?
/* Declare and initialize variables. */
double km, miles;
here:
/* get the km and mi values from the keyboard*/
printf("Enter distance in kilometers:");
scanf("%lf",%26amp;km);
if km==0 THEN goto here
/* Compute Kilometers to Miles */
miles=km/1.6093340;
/*print Miles */
printf("Kilometers = %f \n", km);
printf("Miles = %f \n", miles);
Reply:#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
int main()
{
/* Declare and initialize variables. */
double km, miles;
/* get the km and mi values from the keyboard*/
printf("Enter distance in kilometers:");
scanf("%lf",%26amp;km);
/* Compute Kilometers to Miles */
miles=km/1.6093340;
/*print Miles */
printf("Kilometers = %f \n", km);
printf("Miles = %f \n", miles);
/*pauses for user to press a button. reason is so that the program doesn't immediately end and still displays the results*/
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment