im reading this one c++ book and one of those examples had % operator so i decided to do simple program to see how it works... when i change the % operator to any other operator then it works fine but like this it doesnt

#include <iostream>

int main()

{

double x;

std::cin >> x;

double y;

std::cin >> y;

double z;

z = x % y;

std::cout << z << std::endl;

return 0;

}

#include <iostream>

int main()

{

double x;

std::cin >> x;

double y;

std::cin >> y;

double z;

z = x % y;

std::cout << z << std::endl;

return 0;

}

The % operator is used only with integers and yields the remainder when one integer is divided by another.

6%3 yields 0

7%3 yields 1

8%3 yields 2

9%3 yields 0

The ordinary division operator when applied to integers yields the truncated integer result of the division.

6/3 yields 2

7/3 yields 2

8/3 yields 2

9/3 yields 3

6%3 yields 0

7%3 yields 1

8%3 yields 2

9%3 yields 0

The ordinary division operator when applied to integers yields the truncated integer result of the division.

6/3 yields 2

7/3 yields 2

8/3 yields 2

9/3 yields 3

Topic archived. No new replies allowed.