|
|
You could at least post the code that has the statement you're inquiring about. 1 2 3 int a = 100; a -= 100; ^is that what you had in mind? |
a
is used throughout the program and you can't isolate it to a shorter chunk of code that can be posted here, try using a debugger and tracking the value of a
as the program progresses. Maybe it's getting changed somewhere unexpectedly. We don't mean posting your ENTIRE code. Just the line/statement/chunk/function/section that has what you're asking about. Otherwise, the community would just be guessing at what you're trying to do or what you've done so far. |
|
|
power = power - stardockptr->consumption;
Have you tried printing out the values of power and stardockptr->consumption before this line with the assignment? power = power - stardockptr->consumption; |
Have you tried printing out the values of power and stardockptr->consumption before this line with the assignment? power = power - stardockptr->consumption; No... But I'll see. |
|
|
|
|
For switch statements, if you don't have a break statement at the end of the case statement, it will go to the next case statement. So, for example the following code will print "abcd". switch (myVariable) { case 1: cout << "a"; case 2: cout << "b"; case 3: cout << "c"; case 4: cout << "d"; } The following code would only print out "a" if myVariable is 1. switch (myVariable) { case 1: cout << "a"; break; case 2: cout << "b"; break; case 3: cout << "c"; break; case 4: cout << "d"; break; } So in your code, you have "if" and "else if" statements in most of your case statements. If the if is false, and the else is false (which will happen if power == stardock->consumption), you will not hit a break statement, and you will go to the next case statement. I bet you need a "break;" statement after all the else if statements in your case statements. |