Quadratic Formula

I made a quadratic formula calculator in xcode, but it says "invalid suffix on integer constant" Please help

#include <iostream>
#include <math.h>
using namespace std;

int main() {

double a;
double b;
double c;
char cont;
cout << "Welcome to the quadratic formula/equation calculator." << endl;
cout << "Just incase you forgot, the quadratic formula is..." << endl;
cout << " " << endl;
cout << "For, ax² + bx + c = 0" << endl;
cout << " " << endl;
cout << " -b² ± √(b² - 4ac)" << endl;
cout << "x= -----------------" << endl;
cout << " 2a " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Enter a" << endl;
cin >> a;
cout << "Enter b" << endl;
cin >> b;
cout << "Enter c" << endl;
cin >> c;


if ((b*b-4*a*c) < 0) {
cout << "x is an imaginary number." << endl;

string cont;
while(cont != "Go" && cont != "go" && cont != "GO")
{
cout << "to find the imaginary solution type \"Go\"" << endl;
cin >> cont;

if (cont == "Go" || cont == "go" || cont == "GO")
{
}
else
{
cout << "Please Try Again" << endl;
}

}
}


cout << "x=" << (-(b*b) + sqrt(b*b - 4*a*c))/2a << endl;
cout << "x=" << (-(b*b) - sqrt(b*b - 4*a*c))/2a << endl;

}
else ((b*b-4*a*c) > 0) {

cout << "x=" << (-(b*b) + sqrt(b*b - 4*a*c))/2a << endl;
cout << "x=" << (-(b*b) - sqrt(b*b - 4*a*c))/2a << endl;
}

}
2*a, not 2a.
Also, the else is invalid, and you're not checking that a!=0. I can't verify anything else because I can't figure out what in God's name you wrote.
Last edited on
closed account (z05DSL3A)
You also have a problem with mismatched braces and the final else is out of place.
Edit: to slow
Last edited on
thank you i forgot the * symbol and that a!=0 i did not know what missing bracet you were talking about so please specify this is my most recent code:

#include <iostream>
#include <math.h>
using namespace std;

int main() {

double a;
double b;
double c;
char cont;
cout << "Welcome to the quadratic formula/equation calculator." << endl;
cout << "Just incase you forgot, the quadratic formula is..." << endl;
cout << " " << endl;
cout << "For, ax² + bx + c = 0" << endl;
cout << " " << endl;
cout << " -b² ± √(b² - 4ac)" << endl;
cout << "x= -----------------" << endl;
cout << " 2a " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Enter a" << endl;
cin >> a;
cout << "Enter b" << endl;
cin >> b;
cout << "Enter c" << endl;
cin >> c;


if ((b*b-4*a*c) < 0) && (a!=0) {
cout << "x is an imaginary number." << endl;

string cont;
while(cont != "Go" && cont != "go" && cont != "GO")
{
cout << "to find the imaginary solution type \"Go\"" << endl;
cin >> cont;

if (cont == "Go" || cont == "go" || cont == "GO")
{
cout << "x=" << (-(b*b) + sqrt(b*b - 4*a*c))/2*a << endl;
cout << "x=" << (-(b*b) - sqrt(b*b - 4*a*c))/2*a << endl;
}
else
{
cout << "Please Try Again" << endl;
}

}
}

if (a==0) {
cout << "The answer is undifined." << endl;

}

else ((b*b-4*a*c) > 0) && (a!=0) {

cout << "x=" << (-(b*b) + sqrt(b*b - 4*a*c))/2*a << endl;
cout << "x=" << (-(b*b) - sqrt(b*b - 4*a*c))/2*a << endl;
}


}
well i figured it out myself. thanks anyway
Topic archived. No new replies allowed.