Can someone please help me with this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include<cstdlib>
#include<iostream>
int main()
{
int i;
for(i=1;i<6;i++)
{
if(i%5!=0);
std::cout<<i<<" "<<i%5<<std::endl;
}
system("pause");
return 0;
}
|
Why does the console window show this:
Since the remainder of 5/5 is 0, 5 0 shouldn't be printed out, right?
Last edited on
Just a guess, but if you put parenthesis around i%5, it might work.
I already tried. Doesn't work. Neither does this:
1 2 3 4 5 6 7 8 9 10 11
|
#include<cstdlib>
#include<iostream>
int main()
{
int i;
i=5%5;
if(i!=0);
std::cout<<i;
system("pause");
return 0;
}
|
The output is 0. Doesn't make any sense to me.
Last edited on
Unless you are a complete beginner with one of your first programs, you are about to feel really stupid.
Semicolons mark the end of a statement. "if(anything);" will be completely disregarded.
lol, yeah I do feel stupid now. I'm not a complete beginner. Just made a very dumb mistake. Thanks!
I figured you weren't, just wanted to make sure nobody was left out. Everyone makes those mistakes.