Reputation: 1579
I have this code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float sinfa(num1, num2)
{
float fc;
float powers;
if(num1 == ""){
powers = pow(num2,4);
}else{
powers = pow(num1,4);
}
fc = sin(num1-powers+1);
return (fc);
}
float tp(fa,fb,num1,num2)
{
float p;
float fm2 = fa*num2;
float fm1 = fb*num1;
p = (fm2-fm1)/(fa-fb);
printf("%f",fa);
return (p);
}
float main()
{
double num1;
double num2;
float fa;
float fb;
float p1;
clrscr();
printf("Enter number 1: \n");
scanf("%d", &num1);
getch();
printf("Enter number 2: \n");
scanf("%d", &num2);
getch();
clrscr();
fa = sinfa(num1);
printf("%f \n",fa);
getch();
fb = sinfa(num2);
printf("%f",fb);
getch();
clrscr();
p1 = tp(fa,fb,num1,num2);
printf("%f",p1);
getch();
}
i kept getting 0 from the function tp, and the parameters does not enter when i sent them any ideas why? since for sinfa the parameters are sent and it returns a value
thank you
Upvotes: 0
Views: 88
Reputation: 31972
You need to give types to the function parameters.
float tp(float fa,float fb,int num1,int num2)
Otherwise they are considered int
and that leads to confusing effects.
Similarly you should fix
float sinfa(int num1, int num2)
This wont cause a problem, but it is always good to be explicit about what you mean.
Upvotes: 4
Reputation: 17673
always keep one thing in mind, make the habit of mentioning data type of variables at the time of function declaration & function defination. here you have not mentioned type that means it is considering it as default dat typa of
int
.
float tp(fa,fb,num1,num2)
^^missing data type at all parameter, mention data type
Upvotes: 3