Aug 9, 2010 at 5:59pm UTC
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;
}
}
Aug 9, 2010 at 6:51pm UTC
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 Aug 9, 2010 at 6:53pm UTC
Aug 9, 2010 at 6:55pm UTC
You also have a problem with mismatched braces and the final else is out of place.
Edit: to slow
Last edited on Aug 9, 2010 at 6:56pm UTC
Aug 9, 2010 at 7:17pm UTC
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;
}
}
Aug 10, 2010 at 12:57am UTC
well i figured it out myself. thanks anyway