(Visual C ++)我似乎不能得到if和else语句工作与MessageBox相关联 [英] (Visual C++) I can't seem to be getting if and else statements to work in correlation with MessageBox

查看:219
本文介绍了(Visual C ++)我似乎不能得到if和else语句工作与MessageBox相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图得到一个消息框,将有一个答案与是,另一个答案没有。虽然当我试图让这个代码工作正常,它显示对不起,错误的答案的是和否,似乎忽略如果。此外,它甚至不会没有else语句。对不起,如果这是一个容易的问题,我刚刚开始。这里是代码:

So I'm trying to get a message box that will have one answer with yes, and another answer with no. Though when I try to get this code to work properly it displays "Sorry, wrong answer" for both yes and no and seemingly ignores the "if". Also it won't even work without the else statement there. Sorry if this is an easy question, I've just started. Here is the code:

#include <windows.h>
#include <conio.h>

int main()
{
MessageBox(NULL, "Do farmers grow crops?", "Question", MB_YESNO);
if (IDYES) {

MessageBox(NULL, "You are correct!", "Question", NULL);
}
else {

MessageBox(NULL, "Sorry, wrong answer", "Question", NULL);
}

return 0;
}


推荐答案

int msgID = MessageBox(NULL, "Do farmers grow crops?","Question", MB_YESNO);
if (IDYES == msgID)
{
    MessageBox(NULL, "You are correct", "Question", NULL);
}
else
{
    MessageBox(NULL, "Sorry wrong answer", "Question", NULL);
}

上述代码可以正常工作。

Above code works fine.

这篇关于(Visual C ++)我似乎不能得到if和else语句工作与MessageBox相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆