delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/22/01:17:45

Message-ID: <3B833D24.B017E0CB@earthlink.net>
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
X-Mailer: Mozilla 4.77 [en] (Win95; U)
X-Accept-Language: en,zh-CN,fr,de-CH,ru
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: loop/continue problem
References: <3B8D1069 AT MailAndNews DOT com>
Lines: 57
Date: Wed, 22 Aug 2001 05:03:35 GMT
NNTP-Posting-Host: 64.152.171.184
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread2.prod.itd.earthlink.net 998456615 64.152.171.184 (Tue, 21 Aug 2001 22:03:35 PDT)
NNTP-Posting-Date: Tue, 21 Aug 2001 22:03:35 PDT
Organization: EarthLink Inc. -- http://www.EarthLink.net
X-Received-Date: Tue, 21 Aug 2001 22:00:14 PDT (newsmaster1.prod.itd.earthlink.net)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ramy Elmeligy wrote:
> 
> 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, ...
 
> #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;
> }

#include <iostream>
using namespace std;

int main()
{
    for (int number = 0; number <= 30; number++) {
        if (number % 3 && number % 5)   /* mha - note '%' operator */
            cout << number << endl;
    }
    return 0;
}

1
2
4
7
8
11
13
14
16
17
19
22
23
26
28
29

- Raw text -


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