Hi;

I am new to MFC applications and working on a MCQ based game in Visual C++ using MFC. I have a small question to ask, if I click the option (a-d) that is correct, the game increases score and displays msg "correct' , but I am not able to make it show the correct option if a user selects an incorrect option. like a mesbox showing "Incorrect. Correct op is A".
Here is my code for correct option selection.

void CI2T::IsCorrect(CString s)
{
	KillTimer(0);
	m_time.SetWindowTextA("30");
	if(s == correct)
	{
		score++;
		MessageBox("CORRECT");
		CString s;
		s.Format("%d",score);		
		m_score.SetWindowTextA(s);
	}
	else
		MessageBox("INCORRECT");
	   

}

The code for option selection is here. same for options a-d

void CI2T::OnBnClickedI2tOpta()
{
	if(!end)
	{
		IsCorrect(opA);
		m_OptA.SetCheck(0);
		if(Check())
			Rungame();
		
	}

}

Also, the game time is being maintained, is it possible that I can kill timer during the game, e.g. I have started the game and somebody interrupts me for say 30 sec, once I come back to game, the question has passed. Can I use some keystroke to pause the game at that state and resume it again with the same keystroke when I am ready to play it again.

I'll appreciate any help or suggestions in this regard.

I was looking forward to find some help in this regard from the expert guys but I think it's difficult to get an idea here.

I was looking forward to find some help in this regard from the expert guys but I think it's difficult to get an idea here.

The answer to the second question is "Yes" -- but there's a catch. YOU have to code your program to do that because there's nothing in MFC or c++ that will do it for you.

Since you are not seeing MessageBox("INCORRECT"); it's apparent that if(s == correct) always evaluates to true (assuming that CI2T::IsCorrect() gets called). Have you tried debugging? Put breakpoints at proper places, so that you'll be able to trace how s is getting its value (and correct too, unless it's a constant).

Also, the game time is being maintained, is it possible that I can kill timer during the game, e.g. I have started the game and somebody interrupts me for say 30 sec, once I come back to game, the question has passed.

If I understood the question right, it is possible. You don't necessarily need to kill the timer, instead maybe have a state variable telling whether or not the game is paused. If paused, then simply don't do anything when the timer fires. But you can do it either way.

Note, I'm assuming that the game is coded 100% by you. If it is not, then you have to dig into the source code to be sure that your changes (e.g. pause/resume) won't break anything.

Can I use some keystroke to pause the game at that state and resume it again with the same keystroke when I am ready to play it again.

Most probably yes.

I think it's difficult to get an idea here.

Well, without seeing the source code, questions like these are quite vague (considering a MFC program). There are a zillion things that could be wrong, maybe more ;)

PS. Last but not least, in the CI2T::IsCorrect() function, you have two variables named s , that's a real bad practice.

I can't help you with MFC, but this: if(s == correct) is most likely not correct unless you have defined 'correct' as some sort of macro or a variable.

If you are trying to compare to a string literal, you need double-quotes (" ") around the literal: if(s == [b]"[/b]correct[b]"[/b]) . Without them, you're trying to compare to a variable named 'correct' instead of the literal "correct".

@mitrmkar
As far as 'INCORRECT' msgbox is concerned, I think what I wrote made you conclude that msgbox doesn't appear. Sorry for that. If you have gone through the code, it's apparent that whenever option is incorrect it will go to else and display msgbox "INCORRECT", I was just asking about aslo showing the correct option alongwith the msgbox "INCORRECT". e.g. if option A is correct & player clicked option B, then game should display msgbox "INCORRECT" and also msgbox "Correct option is B".

For the pause break, yes I know some workouts, e.g. using PreTranslateMesage to pause the game on hit of desired key. But I haven't yet worked it out properly. Well, without seeing the source code, questions like these are quite vague (considering a MFC program). There are a zillion things that could be wrong, maybe more ;) I never said, my code is not working, just not achieving the desired result.

@ Fbody
'correct' in if (s==correct) represents field value of access file which has the correct option for the question and it's working correctly. i.e. on correct option selection, it displays msgbox 'CORRECT'.

>>I was just asking about aslo showing the correct option alongwith the msgbox "INCORRECT". e.g. if option A is correct & player clicked option B, then game should display msgbox "INCORRECT" and also msgbox "Correct option is B".

Well, just format a string to say "INCORRECT. The correct option is A" How you know whether the correct option is A or B will depend on other variables in your program.

As far as 'INCORRECT' msgbox is concerned, I think what I wrote made you conclude that msgbox doesn't appear. Sorry for that.
...
I never said, my code is not working, just not achieving the desired result.

OK, now I understand what you were after. English being far from my native language sometimes makes even simple things hard to really understand (and it's annoying).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.