Question: !@#$% Your C program will do the following tasks: i. Prompt and obtain the coefficients a, b, and c ii. In order to determine whether

!@#$%

Your C program will do the following tasks: i. Prompt and obtain the coefficients a, b, and c

ii. In order to determine whether the roots are complex, it will calculate the quantity b2 4ac

iii. If this quantity is negative, then the program will print out the message "The roots are complex"

iv. If not, the program will calculate the two real roots of the quadratic equation as (b + (sqrt(b2 4ac))/2a and (b (sqrt(b2 4ac))/2a.

sample output:

Enter value for a:

Enter value for b:

Enter value for c:

Roots are: (((depends on values entered)))

Issue:

I have tried to do this project and regardless of what numbers I enter for a,b, and c, I get 0s for the roots in any of the situations in the project statement. also, the type is supposed to be double for the values but whenever i try that i get errors so i have left them as int for now. if someone could change them to type double and correct the issue that is giving me 0s everytime, that would be much appreciated.

Thanks!

My code:

#include #include void getData (int*, int*, int*); int checkSolution (int, int, int); int main() { int a,b,c; getData (&a, &b, &c); checkSolution (a, b, c); return 0; } void getData (int* a, int* b, int* c) { printf(" \tQuadratic Equation: a*x^2+b*x+c = 0"); printf(" \tEnter value for a: "); scanf("%d", a); printf(" \tEnter value for b: "); scanf("%d", b); printf(" \tEnter value for c: "); scanf("%d", c); } int checkSolution (int a, int b, int c) { int d; float root1, root2; if(a == 0 && b == 0) { printf(" \t\tNo Solution!"); return -1; } else { printf("the roots of a and b are: %0.2f\t %0.2f", root1, root2); return 1; } if (a == 0) { float root = -(c/b); printf(" \t\tOnly one solution: %0.2f", root); return -2; } else { printf("the roots of a and b are: %0.2f\t %0.2f", root1, root2); return 2; } d = b*b-4*a*c; if(d<0) { printf("No real roots exist!"); return -3; } else { printf("the roots of a and b are: %0.2f\t %0.2f", root1, root2); return 3; } root1 = (-b + sqrt(d))/(2*a); root2 = (-b - sqrt(d))/(2*a); printf(" \t\tThe two roots are: %0.2f, %0.2f", root1, root2); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!