Please tell the novice programmer what's wrong with the code. The error here is certainly not one. The compiler returns only zeros but the answers in the amount in which it is required. The essence of the program is as follows: the user sets the initial and final values of X as well as the step of changing the variable, the program must pass x through two formulas and from the two results return the largest for each step.
#include <stdio.h> #include <math.h> #include <stdbool.h> #define NUM 108 double startX, deltaX, endX, x, f1, f2; double function1(){ f1 = log(1-NUM/sin(x)); return 0; } double function2(){ f2 = tan(x)/NUM; return 0; } double decideFUNC(){ for(x = startX; x <= endX; x += deltaX){ function1(); function2(); if(function1==function2) printf("max values are the same %f\n", function1); else{ if (function1>function2) printf("%f\n", f1); else printf("%f\n",f2); } } return 0; } int main(){ printf("Enter start value X: \n"); scanf("%d", &startX); printf("Enter delta X: \n"); scanf("%d", &deltaX); printf("Enter ending value X: \n"); scanf("%d", &endX); decideFUNC(); return 0; }
if(function1==function2)andif (function1>function2)- what is compared here? The compiler clearly pointed you to gross errors in these lines. Did you just ignore the compiler diagnostic messages? - AnT