How can solve this !!

Write a program that solve an algebraic equation of the second degree ax2+ bx+c=0.

Hint: 1- You may need to use the built-in math library.
2- Your program should be well commented.

Can you Help Me
we're not going to do the assignment for you.

Try to do it yourself, and if you have trouble or a specific quesiton, then come back and ask us.

Show us what you tried, what you're having trouble with, etc, etc.
I could not understand the question
Can you explain to me !!
Sorry for my bad english

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <math.h>

using namespace 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);}   
Last edited on
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.
Sorry for that :/

But i'm a beginner too.
I did this program yesterday, so i just pasted it here.

Any hint about the algorithm?
Last edited on
Topic archived. No new replies allowed.