Wierd Answers

I have been getting weird answers when decimal numbers are input into a, b, or c variables in my quadratic equation program. I was wondering if anyone would be able to sift through some of my decimal related things in it. I wanted it to find if any of the numbers had decimals, and if any did, multiply all three variables by the smallest decimal's multiple-of-ten-that-would-make-it-zero.

An example of the problem:
a = 1, b = -.02, c = -1.2
output:
240.01 and -240.03

The program also accounts for imaginary numbers.

Here are the areas that I think may be problem areas:

http://pastie.org/private/ohrjpyvgcyuswhdb31ukw

I posted a link because it was kind of lengthy.

The one of the problems is with your globals and their supposed "initialization" in main()
Look at the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
int x = 100;

void printGlobal()
{
    std::cout << x << std::endl;
}

int main()
{
    int x = 500;
    std::cout << x << std::endl;
    printGlobal();
    return 0;
}

Output:
500
100

Did you see the problem?
Last edited on
I did, thanks! It took me a little while to see it, but I did eventually see it.

Sorry, for the late reply!
Topic archived. No new replies allowed.