Solving Quadratic Equations: Invalid Inputs

In summary, the conversation involves a student seeking assistance with a program that reads coefficients for a quadratic equation. The student is struggling to validate input and is asking for help from others. They mention being new to Fortran and their difficulties in understanding the details of the language. Someone offers advice on how to validate input by reading it as characters or a string and checking that it conforms to a real before treating it as such. They also suggest referring to a textbook for further examples.
  • #1
Luke1986
2
0

Homework Statement



IMPLICIT NONE
REAL :: A, B, C, DISCR, X1, X2, x1i, x2i
CHARACTER(3)::ANS,ANS1
! Reads the coefficients for the quadratic equation
33 WRITE(*,*)")"Please enter a *REAL*NUMBER* coefficient ( A )."
READ(*,*)A
WRITE(*,*)"Please enter a *REAL*NUMBER* coefficient ( B )."
READ(*,*)B
WRITE(*,*)"Please enter a *REAL NUMBER* coefficient ( C )."
READ(*,*)C
WRITE(*,*)"The coefficients for A,B,C are",A,B,C

Homework Equations



This is only a little part of the whole program. My question is when I input a invalid character, like a letter or symbol, I want to tell the user that it is a error. Since A,C,B are all real variables how do I ask If I can let the user reenter a new value. Maybe an If statement? But I think you cannot compare reals and character. I am new to fortran my prof keeps failing me its my 4th time taking this course. It is very hard for me to comprehend so much details. Can someone assist me please? thank you!

The Attempt at a Solution

 
Physics news on Phys.org
  • #2
Hi Luke1986! http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif

To validate input, you can read it as characters or a string and check that it conforms to a real before treating it as such.

I'm sure almost any textbook would have this or something similar as an example.

Good luck!
 
Last edited by a moderator:

1. What is a quadratic equation?

A quadratic equation is a polynomial equation of the form ax^2 + bx + c = 0, where a, b, and c are constants and x is the variable. It is called quadratic because the highest degree of x is 2.

2. What are invalid inputs in solving quadratic equations?

Invalid inputs in solving quadratic equations refer to values that do not make the equation valid or solvable. These include imaginary numbers, values that result in division by zero, and non-numeric inputs.

3. How do I know if my inputs are invalid in solving quadratic equations?

You can determine if your inputs are invalid by checking if they satisfy the conditions for a solvable quadratic equation. For example, in the equation ax^2 + bx + c = 0, the value of a must not be equal to 0 for the equation to be solvable. Additionally, if the discriminant (b^2 - 4ac) is negative, the solution will involve imaginary numbers, making the inputs invalid.

4. Can I solve a quadratic equation with invalid inputs?

No, you cannot solve a quadratic equation with invalid inputs. The equation must have valid and solvable inputs in order to find a solution. If the inputs are invalid, the equation is considered unsolvable.

5. How can I avoid invalid inputs when solving quadratic equations?

To avoid invalid inputs, make sure to check the conditions for a solvable quadratic equation and use appropriate techniques such as factoring or the quadratic formula. Also, be mindful of the input values and ensure they are within the appropriate range for the equation.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
482
  • Precalculus Mathematics Homework Help
Replies
14
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
5K
  • Precalculus Mathematics Homework Help
Replies
2
Views
824
  • Precalculus Mathematics Homework Help
Replies
1
Views
761
Replies
4
Views
737
  • General Math
Replies
4
Views
856
Replies
11
Views
986
  • Calculus and Beyond Homework Help
Replies
8
Views
146
Back
Top