• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

my c++ problem

NiKeFiDO

Diamond Member
alright: the problem is my Switch statement does not seem to be working properly -> specifically the correctAnswer variable is not obtaining the value which I am looking for.

The premise of this is to correct the answers of a test from input file test.exe. This is the input:




http://www.fidaofamily.com/Chris/output.bmp
this is the output:
the equation you see if from the input file (which is why some are wrong answers, its not math being done my the code)
the two numbers underneath should be the CORRECT anwer and the CORRECT remainder (if applicable)

wtf is wrong with my correctAnswer variable???
 
when i add breaks to the switch statement i get more errors...

error: run-time check failure #3 - the variable 'remainder' is being used without being defined


plz note that it IS previously defined ...

however, the correctAnswer variable is getting the correct value
 
Just taking a cursory look at the program, don't you need a break; within each case statement? Otherwise it will all fall through.
 
read above 😀
however, correctAnswer seems to be taking on the value of int3 rather than the values being assigned in each appropriate case.
 
Just an FYI that you can use the "attach code" button if you're dealing with programming. Makes it a bit easier to read IMO.
 
Originally posted by: NiKeFiDO
error: run-time check failure #3 - the variable 'remainder' is being used without being defined


plz note that it IS previously defined ...

Where?
If you change the remainder declaration to int [...],remainder = 0, and add the breaks to the switch-case block, I think it would work fine.

 
Originally posted by: MSCoder610
Originally posted by: NiKeFiDO
error: run-time check failure #3 - the variable 'remainder' is being used without being defined


plz note that it IS previously defined ...

Where?
If you change the remainder declaration to int [...],remainder = 0, and add the breaks to the switch-case block, I think it would work fine.

these have both been done and seems fine BUT

the correctAnswer variable is stil taking on the value of int3 rather than what is in the cases as it should



i have updated my code
 
mmm might have figured it out..

in my if state i have

if (correctAnswer = int3) instead of if (correctAnswer == int3)

seems to work...
 
Originally posted by: NiKeFiDO
if (correctAnswer = int3) instead of if (correctAnswer == int3)

I'm pretty sure that if (correctAnswer = int3) has the same effect as correctAnswer = int3 before the if statement. You'll have to use a double equals sign to read the value and not write it.
 
Originally posted by: xtknight
Originally posted by: NiKeFiDO
if (correctAnswer = int3) instead of if (correctAnswer == int3)

I'm pretty sure that if (correctAnswer = int3) has the same effect as correctAnswer = int3 before the if statement. You'll have to use a double equals sign to read the value and not write it.

way ahead of ya lol...


still havin problems if how to say correct or incorrect because I have to say if the answer is right say yes
and if the question has a remainder both have to be correct for the answer to be correct


i suck @ teh logic
 
Back
Top