Cannot seem to subtract negative double

hi,

In my bit of code, when I pass in a double value, it doesn't seem to subtract it, rather it adds using that value

1
2
3
4
5
6
7
8
9
10
11
12
13
double amt = 0.0;
cout << "Amount: ";
cin >> amt;

obj.payFee(amt);

payFee(double amt) {
    if(amt >= 0) {
        total += amt;
    } else if(amt < 0) {
        total -= amt;
    }
}


The problem I'm having is when I put in a negative value (e.g -0.20), it adds 0.20 instead... Even if I pass in a direct value (meaning not using cin), it still adds it

Any ideas why?
i suggest a math refresher. its good to know the bare basics of math. when you subtract a negative, it adds them. short of writing your own Double class, there is no way around this. a basic rule of math is that when subtracting a negative, its added instead
Haha oh my god, I can't believe I spent like an hour debugging all of this =/

I feel dumb right now. Thank you for that input, without it I'd probably be spending more hours figuring out why
Topic archived. No new replies allowed.