Mail Archives: djgpp/2001/08/21/20:57:55
OK, i have another question.
This a program i wrote for a simple excercise, given in Ivor Horton's
Beginning C++.
Its supposed to output numbers from 1 to 30, except for those which are
divisible by 3 or 5, using either a for, while, or do-while loop.
This seems as if it should work fine, but the program outputs all numbers from
one to 30, not excluding those it should.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int count = 0;
for(int number = 0 ; count <= 30 ; number++)
{
count++;
if(number / 3 == 0 || number / 5 == 0) //i suspect the problem is
here
continue;
else
cout << number
<< endl;
}
return 0;
}
I've tried removing the continue, and putting an '!' in front of the
statements inside the 'if', then making it so 'cout << number' only executes
when it is false, and that produced the same results! what is going on here?
------------------------------------------------------------
Get your FREE web-based e-mail and newsgroup access at:
http://MailAndNews.com
Create a new mailbox, or access your existing IMAP4 or
POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------
- Raw text -