Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rodrigo Santillan
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- void discrim(int a, int b, int c);
- int main()
- {
- int a;
- int b;
- int c;
- char re;
- cout << "This program will calculate the roots of your quadratic. \nEnter your coeffecients of your quadratic.\n";
- do
- {
- cin >> a >> b >> c;
- cout << "Your quadratic equation is:\n" << a << "x^2";
- if (b > 0)
- {
- cout << "+" << b << "x";
- }
- else
- {
- cout << b << "x";
- }
- if (c > 0)
- {
- cout << "+" << c;
- }
- else
- {
- cout << c << endl;
- }
- cout << "\nWould you like me to calculate some more roots? (y or n)\n";
- cin >> re;
- if ( re == 'y')
- {
- discrim(a, b, c);
- break;
- }
- else
- {
- cout << "Program will now exit\n";
- break;
- }
- } while (re == 'y');
- return 0;
- }
- void discrim(int a, int b, int c)
- {
- int z = (pow(b, 2) - 4 * a * c);
- if (z > 0)
- {
- int x1 = (-1 * b + sqrt(z));
- int x2 = (-1 * b - sqrt(z));
- cout << "Your Roots are x = " << x1 << " and x = " << x2 << endl;
- }
- else if (z == 0)
- {
- int xonly = (-1 * b) / (2 * a);
- cout << "Your only root is x = " << xonly;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment