Help! This is written just like another program I have done which works fine! I have listed variables, all float. My placeholders are all %.2f Compiler error pasted below also. Below the compiler errors, I have pasted my other program that "works". They are similar, only the non working program has an extra line of printf and scanf before outputting the answer. What's wrong??
Code:
#include <stdio.h>
main ( )
{
float price ;
float eps ;
float pem = (price/eps) ;
printf ("Enter Current Stock Price: ") ;
scanf ("%.2f", &price) ;
printf ("Enter Current Earnings Per Share: ") ;
scanf ("%.2f", &eps) ;
pem = (price/eps) ;
printf ("PEM: %.2f\n", pem) ;
return 0 ;
}
Scott-Deans-MacBook-Pro:documents scottdean$ gcc ~/documents/pem.c
/Users/scottdean/documents/pem.c: In function main:
/Users/scottdean/documents/pem.c:14: warning: unknown conversion type character . in format
/Users/scottdean/documents/pem.c:17: warning: unknown conversion type character . in format
Working program:
#include <stdio.h>
main ( )
{
int r ;
float pi = 3.14 ;
float volume = (4.0/3.0)*(pi)*(r*r*r) ;
printf ("Enter radius of sphere: ") ;
scanf (" %d" , &r ) ;
volume = (4.0/3.0)*(pi)*(r*r*r) ;
printf ("Volume of a sphere: %.2f\n" , volume) ;
return 0 ;
}
Last edited by a moderator: