I've only recently started programming with C, and this problem has come up a few times. My code compiles fine, but when I run the .exe and enter my input in the command prompt window, I can see the next line for a fraction of a second before the window closes. Here is an example:
CODE
#include <stdio.h>
void print_converted(int pounds)
/* Convert U.S. Weight to Imperial and International
Units. Print the results */
{ int stones = pounds / 14;
int uklbs = pounds % 14;
float kilos_per_pound = 0.45359;
float kilos = pounds * kilos_per_pound;
printf(" %3d %2d %2d %6.2f\n",
pounds, stones, uklbs, kilos);
}
main()
{ int us_pounds;
printf("Give an integer weight in Pounds : ");
scanf("%d", &us_pounds);
printf(" US lbs UK st. lbs INT Kg\n");
print_converted(us_pounds);
}
When I enter a number for the pounds, say 20, I can see the next line appear but then the window immediately closes. If anyone can offer a solution to this, I would greatly appreciate it.