samedi 15 novembre 2014

Quadratic Equation c++


Vote count:

0




I just stared learning c++ 2 months ago, iam aware that im a beginner.


I am writing a program for users to input for a, b, c to find the quadratic equation.


Please help so I can learn my errors thank you very much.



#include < iostream>
#include < cmath>
#include < string>


using namespace std;

//////Quadratic Formula///////

int a;

int b;

int c;

float top1;

float left1;

float left2

float under3;

float under4;



int main()

{

////////////////////User Input a, b, c///////////////////////

cout << "This program will allow you to input numbers for variables a, b, and c to find the quadratic equation" << endl;

cout << "Enter a number for a: ";
cin >> a;

if (a == 0) //If user enters 0 it will quit the program and give them error message.
{
cout << "0 is not a sufficient coefficient for this program.";
cout <<"Restart now and try again." << endl;
exit(0);
}

cout << "Enter a number for b: ";
cin >> b;
cout << "Enter a number for c: ";
cin >> c;

//////////////Calculations////////////

//////////////////b add
float top1 = (b*b)- 4*a*c);

float left1 = (-b) + sqrt(top1);

float under3 = (left1))/(2*a);

/////////////b subtract

float top1 = (pow(b,2) - 4*a*c);

float left2 = (-b) - sqrt(top1);

float under4 = (left2))/(2*a);




cout <<"The Answer for the Quadratic equation is:";
cout << under3(a, b, c,) <<endl; // function call


cout <<"The first Root Value = " << under3 << endl;
cout <<"The second Root Value = " << under4 << endl;


system("pause") ;

return 0;
}



//px = (-b + sqrt(b * b - 4 * a * c)) / (2 * a)
//nx = (-b - sqrt(b * b - 4 * a * c)) / (2 * a)


asked 22 secs ago







Quadratic Equation c++

Aucun commentaire:

Enregistrer un commentaire