Professional Documents
Culture Documents
ax+ab=0
If the user wants to practice quadratic equations it will ask, given numbers a
and b what the solution is of equation
2
x + (a + b) x + a b = 0
The solutions to this equation are -a and -b. The user has to guess one of
these.
Set the random seed such that it selects different random numbers each time
you run the program. Set the seed only once in your program.
1. The first problem is that the program does not work if you do not enter a
number as answer (What does happen if you enter a letter 'x'?).
2. The other is that it will sometimes print formulas like:
21
The term + -20 is wrong. It should read x^2 + 8 x - 20 = 0.
Use the two functions readint and signchar to fix those problem. Note, you do
not have to change those functions. You just have to use them at the
appropriate places in the program.
NB: fabs(x) returns the absolute value of x.
Programming Exercise 2.9.4 - Counting
The program tutor01.cpp does count the number of successful answer
(variable score), but does not count how many tries have been made. Add a
variable such that the program counts the number of tries, and prints at the
end the score and the number of tries.