cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
% operator problem
% operator problem
Feb 22, 2013 at 11:50pm UTC
henkka
(1)
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;
}
Feb 22, 2013 at 11:51pm UTC
MrHutch
(1822)
Change your doubles to integers and it'll work just dandy.
Feb 22, 2013 at 11:57pm UTC
Alrededor
(166)
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
Topic archived. No new replies allowed.