### How to streamline my program

This is my completely revised program on factoring trinomials. I was wondering if there was any way to make this program more efficient. Thank you in advance!

 ``12345678910111213141516171819202122232425`` ``````#include #include using namespace std; int main() { double a,b,c,n,m,o,x,y; cout << "Use the format ax^2 + bx + c to input the following\nvariables so I can factor the trinomial for you :D\n"; cout << "Please input a: "; cin >> a; cout << "Please input b: "; cin >> b; cout << "Please input c: "; cin >> c; n=sqrt((b*b)-(4*a*c)); m=(b*-1) + n; o=(b*-1) - n; x=m/(a*2); y=o/(a*2); cout << y << ", " << x; cin.ignore(); cin.get(); return 0; }``````
What do you mean by "streamline" and "effficient"?
Faster? Easier to read? Parts might be easily reused? Program is error-prone?
I would recommend setting your double values when you declare them.

I would also write it so that you can enter a, b and c from the command line.
By doing that you could script it later and it would be more useful than having someone sit at a keyboard typing numbers.

If your only calculating one number, and the computer is waiting on user input, then I think your code is fine. If your planning to calculate a million numbers, you might notice a small speed increase if you combine line 16 with 17 and 18, line 17 with 19 and line 18 with 20.

Remove line 23, it's not needed, if you run from a prompt.

BTW, there seems to be a problem with your formula
`n=sqrt((b*b)-(4*a*c));`
Last edited on
Topic archived. No new replies allowed.