#include <stdio.h> // TODO: Declare a Quadratic_Solution enumerated type here: enum Quadratic_Solution { TWO_COMPLEX, ONE_REAL, TWO_REAL }; enum Quadratic_Solution get_solution_type(float a, float b, float c); void print_solution_type(enum Quadratic_Solution qs); int main(void) { float a_coefficent = 0.0f; float b_coefficent = 0.0f; float c_constant = 0.0f; printf("y = ax^2 + bx + c\n"); printf("a? \n"); scanf("%f", & a_coefficent); printf("b? \n"); scanf("%f", & b_coefficent); printf("c? \n"); scanf("%f", & c_constant); enum Quadratic_Solution result = get_solution_type(a_coefficent, b_coefficent, c_constant); print_solution_type(result); return 0; } // TODO: Define the get_solution_type function here: enum Quadratic_Solution get_solution_type(float a, float b, float c) { float result = b * b - 4 * a * c; if(result>0) { return TWO_REAL; } else if(result==0) { return ONE_REAL; } else { return TWO_COMPLEX; } } // TODO: Define the print_solution_type function here: void print_solution_type(enum Quadratic_Solution qs) { switch(qs) { case TWO_COMPLEX: { printf("Two complex solutions.\n"); break; } case ONE_REAL: { printf("One real solution.\n"); break; } case TWO_REAL: { printf("Two real solutions.\n"); break; } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter