delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/21/20:57:55

X-WM-Posted-At: MailAndNews.com; Tue, 21 Aug 01 20:56:51 -0400
X-WebMail-UserID: Ramiman12
Date: Tue, 21 Aug 2001 20:56:51 -0400
Sender: Ramy Elmeligy <Ramiman12 AT MailAndNews DOT com>
From: Ramy Elmeligy <Ramiman12 AT MailAndNews DOT com>
To: djgpp AT delorie DOT com
X-EXP32-SerialNo: 50000000
Subject: loop/continue problem
Message-ID: <3B8D1069@MailAndNews.com>
Mime-Version: 1.0
X-Mailer: InterChange (Hydra) SMTP v3.61.08
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019