my c++ problem

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
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???
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
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
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Just taking a cursory look at the program, don't you need a break; within each case statement? Otherwise it will all fall through.
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
read above :D
however, correctAnswer seems to be taking on the value of int3 rather than the values being assigned in each appropriate case.
 

Tu13erhead

Diamond Member
Mar 28, 2005
3,238
0
76
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.
 

MSCoder610

Senior member
Aug 17, 2004
831
0
71
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.

 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
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
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
mmm might have figured it out..

in my if state i have

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

seems to work...
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
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.
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
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