Ok so first, I would change
srand(time(0))
to
srand(static_cast<signed int>(time(0)));
or
srand(static_cast<signed int>(time(NULL)));
I think it's just for elegance sake really, but at least it specifies that it is a signed integer, I don't think you HAVE to do it, but like I said, for elegance sake (plus some people might be really picky especially the SubrDubrL33bCoderz here)
Next, I don't know why you are doing this
char a, b, c, x1, x2
I think you should change that to
int a, b, c, x1, x2
Next, you have this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
if (a == 0) {
cout << "We cannot divide by 0.";
}
else {
if (determinant > 0) {
x1 = (-b + sqrt(determinant)) / (2 * a);
x2 = (-b - sqrt(determinant)) / (2 * a);
cout << "Result 1: " << x1 << endl;
cout << "Result 2: " << x2 << endl;
}
else if (determinant == 0) {
x1 = (-b + sqrt(determinant)) / (2 * a);
cout << "Result: " << x1 << endl;
}
else {
cout << "No solutionn for x." << endl;
}
}
| |
Why do you have the else, right after the if and then you continue to do elseif?
Check this out:
http://www.cplusplus.com/doc/tutorial/control/
Look at how if/else if/else works.
I haven't done your homework but I thought I'd just show you some things you can change, and I hope you can figure it out.
Edit: Turn your PM's on, maybe I can try to work it out with you
Edit2: For the if{}else part you should do this instead
1 2 3 4 5 6 7 8 9 10 11 12
|
if(a == 0){
// code here
}
else if(determinant > 0){
// code here
}
else if(determinant == 0){
// code here
}
else{
// code here
}
| |
Also, I know that
1 2 3
|
std::cin >> a
std::cin >> b
std::cin >> c
| |
Is cool and all, but you can also just do
std::cin >> a >> b >> c
just for brevity sake I guess, even though the aforementioned method (the one you are using) is probably safer..