gpt4 book ai didi

c++ - 在 C++ 中使用 double 时模数不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 15:44:02 25 4
gpt4 key购买 nike

<分区>

我不被允许使用模组。我认为它不起作用,因为我使用的是 double ;有没有解决的办法? --- 评论区域不起作用

void displayResults(double num1, char oper, double num2)
{
switch(oper)
{
case '+' :
cout << num1 << "+" << num2 << "=" << (num1+num2) << endl;
break;

case '-' :
cout << num1 << "-" << num2 << "=" << (num1-num2) << endl;
break;

case '*' :
cout << num1 << "*" << num2 << "=" << (num1*num2) << endl;
break;

case '/' :
if ( num1==0 || num2==0)
cout <<"A number divided by 0 or divided into 0 is always 0"<< endl;
else
cout << num1 << "/" << num2 << "=" << (num1/num2) /*+ (num1%num2) */ << endl;
break;
// case '%' :
// cout << num1 << "%" << num2 << "=" << (num1%num2);
//break;
}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com