I have just created a program to act as a quadratic root solver. The user inputs the a, b and c values from their ax^2 + bx + c =o equation and the program finds the roots and prints them on the screen or if there are no real roots it prints "There are no real roots to this quadratic equation".

However, the requirement of the program is to be able to cope without crashing if illegal characters (e.g. letters or symbols or .1 etc.) are entered. Ideally it would need to print on the screen "You have entered an illegal character".

Is there a very simple way of coding this function into the program?

The existing code is shown below.

Thanks.

Paul

Code:#include <stdio.h> #include <math.h> main() { float a, b, c, determinate, root1, root2; printf("Enter the required a followed by b followed by c and the program will calculate the roots for you: \n"); scanf("%f %f %f", &a, &b, &c); printf("\n"); determinate = (b*b)-(4.0*a*c); if (determinate>0) {root1 = (((-b)+sqrt(determinate))/(2*a)); root2 = (((-b)-sqrt(determinate))/(2*a)); printf("Root 1 = %8.5f Root 2 = %8.5f\n", root1, root2);} if (determinate == 0) {root1 = (((-b)+sqrt(determinate))/(2*a)); printf("Repeated root = %8.5f \n", root1);} if (determinate<0) printf("There are no real roots to this quadratic equation.\n"); printf("\n"); system ("pause");}