I kept getting Illegal use of character on the line that checks if a variable is empty or null.
Does anyone know why this happened?
the error points here:
if((fa == "" && fp == "") || (fb == "" && fp == "")){
though it worked before i just dont know whats causing this error.
Edit:
changed the code now the errors are too few parameters for function sinfa.
i only want to pass one parameter at a time to this function, is it possible or do i have to create another function to do that so that i can cater to them individually?
thank you. :)
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.14159265359
float sinfa(float num1,float num2)
{
float fc;
float powers;
float rad_angle;
if(num1 != 0){
rad_angle = num1 * (PI / 180.0);
powers = pow(rad_angle,4);
fc = sin(rad_angle)-powers+1;
}else{
rad_angle = num2 * (PI / 180.0);
powers = pow(rad_angle,4);
fc = sin(rad_angle)-powers+1;
}
return (fc);
}
float sinp(float p1)
{
float fop;
float ppowers;
printf("%f",p1);
ppowers = pow(p1,4);
fop = sin(p1)-ppowers+1;
return (fop);
}
float tp(float fa,float fb,int num1,int num2)
{
float p;
float fm2 = fa*num2;
float fm1 = fb*num1;
p = fm2-fm1/fa-fb;
return (p);
}
float main()
{
float num1;
float num2;
float fa;
float fb;
float p1;
float fp;
clrscr();
printf("Enter number 1: \n");
scanf("%f", &num1);
getch();
printf("Enter number 2: \n");
scanf("%f", &num2);
getch();
clrscr();
if((fa == 0 && fp == 0) || (fb == 0 && fp == 0)){
fa = sinfa(num1);
fb = sinfa(num2);
p1 = tp(fa,fb,num1,num2);
fp = sinp(p1);
}else{
if((fa*fp) < 0){
num1 = num1;
num2 = p1;
fa = sinfa(num1);
fb = sinfa(num2);
p1 = tp(fa,fb,num1,num2);
fp = sinp(p1);
}
if((fb*fp)< 0){
printf("\n 2");
getch();
}
}
}
Error appears because you're comparing float with string literal, ie:
if((fa == "")
You can only do a comparison of float with a numeric/float literal, ie:
if((fa == 0.0
Recall that there's no such concept as NULL / uninitialized for primitive type such as float. Instead they typically default to 0.
Hence having the following means f value will be literal 0
float f;