[分享]加法,减法,乘法,除法
对话框的MFC
添加3个edit,1个combobox,1个button
combobox属性设置:
data: +;-;*;/
sort: false
type: drop list
button的caption设为 =
edit分别添加值变量int:m_v1,m_v2,m_ans
combobox添加值变量int: m_oper
button加入如下代码:
void Cadd_sub_mul_divDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(true);
switch(m_oper)
{
case 0:
m_ans=m_v1+m_v2;
break;
case 1:
m_ans=m_v1-m_v2;
break;
case 2:
m_ans=m_v1*m_v2;
break;
case 3:
if(m_v1==0)
{
MessageBox("除法不能为0!");
return;
}
else
m_ans=m_v1/m_v2;
break;
}
UpdateData(false);
}