gpt4 book ai didi

c++ - 在 C++ 中验证乘法值?

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

我必须做一个测试,其中一个数字必须是 500 的倍数

      do{
cout << "Input Price[price>0|price multiple of 500]: ";
cin >> price;
cin.sync(); cin.clear();
} while (price<1 || price>5000);

代码仍然不完整,我只需要添加以下验证就可以了。我该怎么办?

还有这种验证的正确术语是什么?我很难确定标题。

最佳答案

将以下内容添加到您的测试中:

price % 500 == 0

这通常称为 modulo (求两个数的余数):如果你的价格是500的倍数,那么价格和500的余数就是0。

关于c++ - 在 C++ 中验证乘法值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25370498/

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