I want to define a discriminant, but I don't know what to do.
I defined it as follows.
If the discriminant D=b*b-4*a*c>0, it has two solutions, so num=2. If the discriminant D=0, it is complex, so num=1. If the discriminant D<0, it has no solution, so num=0, but it did not compile well.
I think there is no problem with int num_of_ans1a(), but I would like you to tell me what the problem is with int main().
int num_of_ans1a(inta, intb, intc)
{
int num;
if(b*b-4*a*c>0){
num = 2;
} if(b*b-4*a*c=0){
num = 1;
} else{
num = 2;
}
return num;
}
int main (void)
{
intn;
n = num_of_ans1a();
printf("The result is %d.",n);
return n;
}
The reasons for the compilation error are as follows:
=
but is considered an assignment operator and has failed.==
to compare to 0.k As Kunif replied.There are no compilation errors, but there are the following problems:
We defined num = 0 because there is no solution for the discriminant D<0
For the discriminant D<0
, the else in the second if statement is num=2
.
Also, when the first if statement is passed, the else clause of the second if statement is executed.
Else must precede the second if.
int num_of_ans1a()
in the second if
where (b*b-4*a*c=0)
is a substitution rather than a conditional expression.
Wouldn't two =
be (b*b-4*a*c==0)
?
The n=num_of_ans1a();
call in intmain(void)
does not specify any arguments.
Aren't these two the reasons why you can't compile?
addition:
By the way, it's easy to look up and discover by being included in your development environment (some IDE, editor, compiler) or by using customized extensions and Lint tools.
You don't need the questions themselves, or you can write more information and get answers when you ask them.
529 Uncaught (inpromise) Error on Electron: An object could not be cloned
700 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
546 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.