c ++中的模数运算符让我发疯

Jos*_*eph -1 c++

我的名字乔和我遇到了一些c ++中的模数问题

继承人的问题:

#include <iostream>
#include <string> 
using namespace std;

int main()
{
//In short, this is what i am trying to do:
//divide two numbers, and get both the quotient
//and the remainder
//however, as an example, this below produces a remainder
//of 10 
//110 \ 20 should equal 5 remainder 5
int firstInput =110, secondInput = 20;

int quotient = 0, remainder = 0;

quotient = firstInput / secondInput;

remainder = firstInput % secondInput;// i think the problem is here

cout << "The quotient is " << quotient << " and the remainder is "
    << remainder << endl;


system("pause");
return 0; 
}
Run Code Online (Sandbox Code Playgroud)

基本上它没有正确计算余数.任何帮助当然会非常感激.干杯

Jam*_*mes 7

我得到了正确的答案......

The quotient is 5 and the remainder is 10
Press any key to continue . . .  
Run Code Online (Sandbox Code Playgroud)

我认为这个bug可能位于键盘和椅子之间... = P.

  • 哈哈是如此真实,至少你笑容满面,男人我需要刷我的数学,或者其他什么,欢呼:) (2认同)