>Anyways when I execute it
You mean it actually compiles for you? What compiler do you use?
Code:
#include <stdio.h>
/*
** Globals should be avoided when possible.
*/
float a,b,c=0;
float divide(float c,float d);
int main(void)
{
printf("Please enter two numerical values(deciamals are accepted): ");
/*
** Be aware that scanf will expect the user to enter <num>,<num>.
*/
scanf("%f,%f",&a,&b);
/*
** You already did this, there's no need for another prototype.
*/
float divide(float c,float d);
/*
** This is an invalid function call.
*/
c=float divide(float c, float d);
/*
** We are working with floats, right? Why print an integer value then?
*/
printf("Answer: %d", c);
return 0;
}
float divide(float c, float d)
{
/*
** Not needed.
*/
float e=0;
if(d>0)
e=c/d;
else
/*
** This is illegal.
*/
void;
return e;
}
Here is another way to do it, with the errors (mostly)removed. But that is for a later lesson.
Code:
#include <stdio.h>
static float divide(float c,float d);
int main(void)
{
float a, b, c;
printf("Enter two numbers(decimals are accepted): ");
if ( scanf("%f %f",&a,&b) == 2 ) {
c=divide(a, b);
printf("Answer: %.2f", c);
}
return 0;
}
static float divide(float c, float d)
{
if(d > 0.0)
return c / d;
return 0.0f;
}
-Prelude