Article View: alt.comp.lang.learn.c-c++
Article #593Re: A more elegant way than nested if..else ?
From: Wayne McDermott
Date: Sat, 20 Oct 2001 20:40
Date: Sat, 20 Oct 2001 20:40
51 lines
2992 bytes
2992 bytes
"Davlet Panech" <Davlet.Panech@Tellabs.com> wrote in message
news:3BCDC564.8369F6B2@Tellabs.com...
> >
>
> >
> > Hi Davlet,
> > I've compiled and run the source with Borland C++Builder Version 3. If 0
is
> > entered first the program terminates without giving any message (as I
> > intended). Could this behaviour be compiler dependant?
> >
>
> Wayne,
>
> Following is the main function from the latest version of the program you
> posted. Clearly, 0 is a perfectly legal input as far as the current
iteration of
> the loop is concerned: `Year' is not tested until the next iteration; the
body
> of the loop will execute at least once regardless of what the user enters.
I
> can't believe this program ran without printing any messages after being
> compiled by Borland (a very good compiler that couldn't misbehave so
obviously).
>
> main()
> {
> using namespace std;
> while (Year != 0) //Keep going till user enters 0
> {
> cout << "Enter the Year. Enter 0 to quit..." << endl;
> cin >> Year;
> cout << "The first day of " << Year;
> if (Year <= This_Year) //Has the year already passed?
> cout << " was a " << GetFirstWeekDay(Year) << endl;
> else
> cout << " will be a " << GetFirstWeekDay(Year) << endl;
> }
> return 0;
> }
>
Hi Davlet,
Dammit, you're right. I've compiled this under GNU g++ and it prints "The
year 0...etc".
Easily fixed but can the Borland folks tell me why the compilers differ in
their behaviour?
Regards,
Wayne McDermott
Technical Details
Message-ID:
<pmxA7.303$e5.1196@newsfeeds.bigpond.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!crtntx1-snh1.gtei.net!washdc3-snh1.gtei.net!news.gtei.net!portc01.blue.aol.com!news.stealth.net!intgwpad.nntp.telstra.net!newsfeeds.bigpond.com!not-for-mailReferences:
<WFHy7.8916$e5.80161@newsfeeds.bigpond.com> <3bcd34da.34931911@news.ntlworld.com> <uYgz7.10255$e5.93435@newsfeeds.bigpond.com> <3BCDB162.5CD451E7@Tellabs.com> <ETiz7.10294$e5.96293@newsfeeds.bigpond.com> <3BCDC564.8369F6B2@Tellabs.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114592,402e14d3eacdac2 X-Google-Attributes: gid114592,public X-Google-Thread: 102541,ca698d6208b4ec98,start X-Google-Attributes: gid102541,public X-Google-ArrivalTime: 2001-10-21 03:25:54 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!crtntx1-snh1.gtei.net!washdc3-snh1.gtei.net!news.gtei.net!portc01.blue.aol.com!news.stealth.net!intgwpad.nntp.telstra.net!newsfeeds.bigpond.com!not-for-mail From: "Wayne McDermott" <elhombre@bigpond.com> Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cppbuilder.students References: <WFHy7.8916$e5.80161@newsfeeds.bigpond.com> <3bcd34da.34931911@news.ntlworld.com> <uYgz7.10255$e5.93435@newsfeeds.bigpond.com> <3BCDB162.5CD451E7@Tellabs.com> <ETiz7.10294$e5.96293@newsfeeds.bigpond.com> <3BCDC564.8369F6B2@Tellabs.com> Subject: Re: A more elegant way than nested if..else ? Lines: 53 X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: <pmxA7.303$e5.1196@newsfeeds.bigpond.com> Date: Sun, 21 Oct 2001 06:40:11 +1000 NNTP-Posting-Host: 144.138.213.65 X-Trace: newsfeeds.bigpond.com 1003659797 144.138.213.65 (Sun, 21 Oct 2001 20:23:17 EST) NNTP-Posting-Date: Sun, 21 Oct 2001 20:23:17 EST Organization: Telstra BigPond Internet Services (http://www.bigpond.com)