Hello, I just finished, well sorta finished a program I have been working on for my last assignment in my COSC C++ class. I've used all of these components in other programs before, but in this specific condition it is giving me a fit.

The goal of the program is to calculate the conditions of the quadratic formula (will the answer be one root? two roots? or imaginary roots?), and provide the roots if it is one or two. I opted to use a switch statement instead of if/else.

However, It seems either my secondary function is severely messed up, or I just have a small typo. However, I cannot find either.

Code:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int DetermineRootTypes(int a, int b, int c){
if(b * b - 4 * a * c > 0){
return 1;
}
if(b * b - 4 * a * c == 0){
return 2;
}
if(b * b - 4 * a * c < 0){
return 3;
}
return 0;
}
int main(){
int a, b, c;
float root1;
float root2;
int condition;
cout << showpoint << fixed << setprecision(4);
for(int i = 0;i < 3;i++){
cout << "Please input the 3 variables of the quadratic equation. (a, b, and c)." << endl;
cin >> a >> b >> c;
condition = DetermineRootTypes(a,b,c);
switch(condition){ // Switch statements, in which the roots are computed.
case 1:
root1 = (-1 * b * sqrt(b * b - 4 * a * c)) / 2a;
root2 = (-1 * b * ( -1 * sqrt(b * b - 4 * a * c))) / 2a;
cout << "The answer are two real roots." << endl;
cout << "The first is " << root1 << endl;
cout << "The second is " << root2 << endl;
break;
case 2:
root1 = (-1 * b * 0) / 2a;
cout << "The answer is one repeated root." << endl;
cout << "The answer is " << root1 << endl;
break;
case 3:
cout << "The answer is two imaginary roots." << endl;
break;
default:
cout << "Values entered were not numbers." << endl;
break;
}
}
}

Now, for the various errors...

Code:

(42) : error C2668: 'sqrt' : ambiguous call to overloaded function
(42) : error C2059: syntax error : 'bad suffix on number'
(42) : error C2146: syntax error : missing ';' before identifier 'a'

Those pretty much repeat for a few more lines down the code.

Any help would be greatly appreciated. Feel free to flame my horrid coding methods too.