By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

HELPC++program to decide if the coefficients of a quadratic equation have real roots.

P: 1
1. write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real roots” if the discriminant is negative and find the two roots when there is no error condition. DO NOT FIND THE ROOT IF THERE IS AN ERROR CONDITION.
2. use a NESTED DECISION to do the three parts of the algorithm above.
3. write a sentinel-controlled loop based on a character value to control the loop, q or Q will terminate the loop, any other value will continue processing. Read the value from the keyboard and write to the monitor. Use the inputs given below.
4. document the program properly, see page 3 of the syllabus for the correct style. Use format for both the roots. Be sure to set the iosflags, setprecision, and showpoint. Use a setprecision of 3. also use setw for each numeric output.
5. libraries needed: iostream, cmath, iomanip. Add the .h, math.h for other compilers.


Sample input:
For character variable, and A, B, and C, respectively.
T 2.0 -3.0 -7.0
T 0.0 5.5 1.3
K 3.0 -1.0 10.0
Q//the sentinel value
Sample output
The two roots are -1.266 and 2.766 (first input above)
Zero divide (second input above)
No real roots (third input value)

This is what have so far but i am very confused on what order to put it in

#include <iostream>
#include <math.h>
#include <iomanip>

int main (void)
{
float coefficients
float roots

cout<< "Enter three coefficients of a quadratic equation or Q to quit\n";
cin >> num 1, num 2, num 3
Mar 18 '08 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
The order of your numbers is not relevant. What is relevant is that you know what is being entered. That is, if you expect numbers for A, B and C in that order then you need variables for A,B and C. Then when you do your cin>>, you make sure A is the first variable, B the second and so on.

In your code you do not have variables named num1, num2 and num3. All you have are two variables named coefficients and roots. I hope you understand that even though the name is plural, there is just one variable for your coefficients and not three.
Mar 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.