So I have coded this program on formula method .
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
int a , b , c ;
cout << " Enter the values of a , b , c " << endl;
cin >> a ;
cin >> b;
cin >> c;
cout << "Therefore according to the formula : b*b-4ac =" << b*b-4*a*c << endl;
cout << "Therefore x = " << ((-b) + sqrt(b*b-4*a*c)) / (2*a) << " or " <<((-b) - sqrt(b*b-4*a*c)) / (2*a) << endl;
system("pause");
return 0;
}
It works perfectly except that it divides everything . I mean lets take an example of a = 3 , b = 7 , c = 4 .
So the ans which shows up are -1 or -1.33333 but I don't want the second ans in decimal . Rather I would like the second ans as -4/3 .
Any way of doing that ?