i can't figure out the problem in this program

We're supposed to print out the numbers divisible by 3 in between 1 - 100

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int main()
{
	int num=0;
	
	while(num<=99)
	{
		if(num%3==0)
		{
			cout<<num<<" is disible by 3"<<endl;
		}
		
		num++;
	}
	
	return 0;
}

.
The problem is that, it does not print out the numbers from 3 - 36. It starts printing out from 39 and goes till 99
Last edited on
Try running it on the shell (cpp.sh), because I dunno about you, but it works perfectly as intended. I don't see a problem with your code.
I started c++ about a week ago. So, i do not know what (cpp.sh) is.
Strange!
I made this code on Dev-C++ and the error occurred. I compiled it on Dev-C++ and ran it on Dev-C++. Then i made it on notepad and compiled it by myself in cmd, it runs perfectly. But, now it says "0 is divisible by 3". Why is it saying this?
now it says "0 is divisible by 3". Why is it saying this?


Because 0 is divisible by 3.

Real answer though, your num is starting at 0 when you want it to start at one.
Last edited on
By the way, http://cpp.sh is the native shell most of the code from this forum goes to run. You'll notice the little widget-like thing on the top right of your code box whenever you mouse over it.
Topic archived. No new replies allowed.