I've searched the internet for my problem but it won't get solved. I have the following function:
#include <stdio.h>
#include <math.h>
int solve(double a, double b, double c, double *x1, double *x2){
*x1=(-b+sqrt(pow(b,2)-(4*a*c)))/(2*a);
*x2=(-b-sqrt(pow(b,2)-(4*a*c)))/(2*a);
}
int main(void){
double a, b, c;
scanf("%lf", &a);
scanf("%lf", &b);
scanf("%lf", &c);
double x1, x2;
int count= solve(a, b, c, &x1, &x2);
if(!count){
printf("no solution");}
else if(count==1){
printf("one solution x: %lf", x1);}
else if(count>1){
printf("two solutions x1: %lf x2: %lf", x1, x2);}
}
the program should return both values from the function solve but everytime I start the program I have a warning that says "missing return value". Where is my fault? By the way struct is not an option cause of restrictions from my professor and it need to be all done in one function.
intbut you're not returning anything (there's noreturnstatement).solveas returning anintusing the regular return value (in addition to whatever it does with the output parameters), but you never actually do that. You can do that withmainbecause it’s special-cased to mean 0, but for any other function that’s undefined behavior.b² =4*a*c? How does it communicate that there is no solution ifb² <4*a*c? Themainfunction is expecting the regular return value to be the number of solutions, but thesolvefunction doesn’t calculate that information, and just leaves it as NaN for no solution or equal values for one solution.