C programming.. integer to float !!

Hi guys, I had a little bit problem while trying to input fractional values to calculate types of physics applications.. My question is how to calculate the values into float numbers rather than integers?? Thanks in advance :)


#include <stdio.h>
#include <conio.h>
#include<stdlib.h>





float main ()
{
int select, f, m, d, v, work, energy, momentum;
printf("\t\t========select the formulla======== \n");
printf("1- Momentum\n");
printf("2- Work\n");
printf("3- Energy\n");
printf("4- Go back\n");
printf("\n\n\nYour option [ ]\b\b");
scanf("%d", &select);

switch (select ){

case 1:
system("cls");
printf("Enter mass value in kilogram : \n");
scanf("%f", &m);
printf( "Enter velocity in meter per second: \n");
scanf("%f", &v);
momentum = m*v;
printf("Momentum of the body is %0.3f kg-m/sec\n\n " ,momentum);
break;

case 2:
system("cls");
printf( "Enter force value in Newton: \n");
scanf("%f", &f);
printf( "Enter distance value in meters : \n");
scanf("%f", &d);
work = f*d;
printf("Work is = %0.3f joule(J)\n\n ",work);
break;


case 3:
system("cls");
printf( "Enter mass value in kilogram: \n");
scanf("%f", &m);
printf( "Enter velocity in meter per second : \n");
scanf("%f", &v);
energy = (m*v*v)/2;
printf("Energy is = %0.3f joule(J)\n\n",energy);
break;





}

getch();
return 0;
}

Last edited on
Change int to float (except for 'select') and "%d" to "%f".
dude hamster, I changed as what u typed, it doesn't work too!!
"It doesn't work" isn't a very useful problem description.
I need assistance by looking to my codes above and see what code it misses..
You never said what's wrong. Does it not compile? Does it not output what you want? If so, what does it output and what do you want it to output?
I want it to output fractional numbers, I mentioned it in the question above the program :) .. I'm sorry for not being specific.. anyway, after changing int to float and "%d" to "%f", I got nothing in output !!
You really don't realize that it's nigh impossible to tell what you actually have right now without showing us what exactly you changed? Though it's likely that you're reading select as a float, then the case statement won't work.
Topic archived. No new replies allowed.