Basic Programme giving Error

dharmil007

Journeyman
Joined
May 26, 2010
Messages
247
HeLLo i m new to C & trying to learn it.
i Wrote a programme but when it runs it givese the values as GARBAGE values.
i Dont know why ??
So can pls anybody gimme a solution

PHP:
/*The distance between 2 cities {in km.} is input through 
the Keyboard.WAP to convert & print thsi distance in meters, 
feets, inches & centimeters*/
#include <stdio.h>
#include <conio.h>
void main ()
{
	float cm, km, ft, inch, mtr;
	clrscr ();
	printf ("\nEnter Distance {in km} between 2 cities\n");
	scanf ("\n%f", &km);
	printf ("\nThe distance between 2 cities is %fkm",km);
	mtr = 1000.0*km;
	ft = 3280.8399*km;
	cm = 100000.0*km;
	inch = 39370.0787*km;
	printf ("\nThe Convertsion of km to diff units\nMETER = %f\nFEET = %f\nCentiMeter = %f\niNChEs = %f", &mtr, &ft, &cm, &inch);
	getch ();
}
 

Liverpool_fan

Sami Hyypiä, LFC legend
Joined
Jun 19, 2007
Messages
2,187
scanf ("\n%f", &km);
Remove the "\n" in this line. Write as:
scanf ("%f", &km);

Also:
Don't use Turbo C++, Use MinGW instead as compiler, Geany as IDE
Use int main() and return 0 instead of void main(), main() should always return int in standard C
Don't use clrscr() and getch() or anything which relates to conio.h
Ignore the above if you are more interested in marks than learning.
 

vamsi360

Always confused
Joined
May 10, 2008
Messages
348
Regarding C++ style of programming, learnt it from the creator himself! I am greatly influenced by his website for some time.

*www2.research.att.com/~bs/bs_faq2.html
 
Top