#include <iostream>
#include <math.h>
usingnamespace std;
int delta(int a,int b, int c){
int r;
r=((b*b)-(4*a*c)); // Calculate delta
return r;}
int main(){
int a,b,c;
float x1,x2;
cout << "Quadratic eq solver" << endl;
do{
cout << "Input a: ";
cin >> a;
if (a==0)
break;
cout << "Input b: ";
cin >> b;
cout << "Input c: ";
cin >> c;
if (delta(a,b,c)>=0){
x1=(-b+sqrt(delta(a,b,c)))/2*a; //Solves with bhaskara
x2=(-b-sqrt(delta(a,b,c)))/2*a; //Solves with bhaskara
if (x1!=x2) //If delta > 0 then show the value of X
cout << x1 << ", " << x2 << endl; //If x1 is ot equal to x2 show the two values
else // Else the show only the value of x1
cout << x1 << endl;}
else
cout << "Negative delta!" << endl;
cout << "------------------------------\n\n";}
while (a!=0);}
I'm sure that code could have been made even less complicated and optimized a lot without too much effort. Besides: Why did you do his homework for him?
Disadvantages:
- You wasted your time on something which is below your level (because you could easily write it).
- You encourage people to not do their homework, therefor not learning C++.
- You will be hated on these forums.