Data validation problem.


Joined
Mar 31, 2012
Messages
1
Reaction score
0
Hii guys ,
i've to create a program for my assignment that calculate no of mol , pressure , volume and temperature.
and the code appears to be like this ,
float vol , mol , temp , pressure;

printf("Please enter the volume : ") ;
scanf("%f", &vol) ;

printf("Please enter the number of mole : ") ;
scanf("%f", &mol) ;

printf("Please enter the temperature : ") ;
scanf("%f", &temp) ;

pressure=(mol*0.082057*temp)/vol ;

printf("The pressure is %.2f\n\n", pressure) ;
the problem is whenever i input alphabet the program will go insane. Can anyone help me to solve this problem? The input can be only numerical values , others than that it will prompt the user to reenter the input. Have to pass up on monday. :(
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top