🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: de.comp.lang.c++
3 messages
3 total messages Started by Marco Linke Sun, 08 Oct 1995 12:09
Problem-Countdown?
#534
Author: Marco Linke
Date: Sun, 08 Oct 1995 12:09
39 lines
1158 bytes

Hi,


ich bin noch ein blutiger Anfänger in Sachen C++.
Ich wollte einfach nur einen kleinen Countdown Zaehler
schreiben, was mir aber einfach nicht gelingt. Ich schreibe
mal mein Listing

#include <iostream.h>
#include <conio.h>


int x;
void main ()
{
   do {
       for (x = 10; x < 1; --x)
       cout << endl << x;
      }

       while (x !=0);
       getch();
    }

Das Programm soll einfach nur von 10 an rueckwärts zaehlen und bei null  
das Programm anhalten.

Ich möchte mich schon im vorraus an alle bedanken....

....Ciao Marco

       _Telefon_ .....0331/621770
        _E-Mail_ ......Mac@Admiral.berlinet.de

(c)1995 Marco Linke

## CrossPoint v3.1 ##
Re: Problem-Countdown?
#537
Author: Bernd Eggink
Date: Mon, 09 Oct 1995 12:07
46 lines
1822 bytes
On Sun, 8 Oct 1995, Marco Linke wrote:

> ich bin noch ein blutiger Anfänger in Sachen C++.
> Ich wollte einfach nur einen kleinen Countdown Zaehler
> schreiben, was mir aber einfach nicht gelingt. Ich schreibe
> mal mein Listing
> 
> #include <iostream.h>
> #include <conio.h>
> 
> 
> int x;
> void main ()
> {
>    do {
>        for (x = 10; x < 1; --x)
>        cout << endl << x;
>       }
> 
>        while (x !=0);
>        getch();
>     }
> 
> Das Programm soll einfach nur von 10 an rueckwärts zaehlen und bei null  
> das Programm anhalten.
> 

Kleiner, aber wirkungsvoller Fehler im Schleifenkopf:

  for (x = 10; x > 0; --x)

muss es heissen. Im uebrigen, was soll diese while-Schleife?? Sie
ist entweder wirkungslos (x == 0) oder fuehrt dazu, dass das Programm
sich aufhaengt (x != 0).
Ausserdem wuerde ich conio nicht ohne Not verwenden - es ist DOS-
spezifisch und damit nicht portabel.

Gruss
	Bernd

+----------------------------------+
|          Bernd Eggink            |
|    Rechenzentrum Uni Hamburg     |
| admin@rzaix13.rrz.uni-hamburg.de |
+----------------------------------+
Re: Problem-Countdown?
#538
Author: Kreikenbohm
Date: Mon, 09 Oct 1995 19:46
33 lines
1437 bytes
Hi Marco

In article <5vS4hQwd$wB@p0000328.admiral.berlinet.de>,
   mac@admiral.berlinet.de (Marco Linke) wrote:
>#include <iostream.h>
>#include <conio.h>
>
>int x;
>void main ()
>{
>   do {
>       for (x = 10; x < 1; --x) 
                     ^^^^^ so wie laeuft die Schleife, solange
                           x < 1 ist. Dies ist jedoch nie der Fall (x = 10)
                           Damit wird die --x nie durchgefuehrt.
                           Es muss heissen:
                           for (x = 10; x >= 0; x--); // x = 10 .. 0
                           oder 
                           for (x = 10; x > 0; x--);  // x = 10 .. 1
>       cout << endl << x;
>      }
>
>       while (x !=0);
        ^^^^^^^^^^^^^       wozu Du die do-while brauchst, weiss ich nicht.
                            lass sie einfach weg ;-)
>       getch();
>    }
>
>Das Programm soll einfach nur von 10 an rueckwärts zaehlen und bei null  
>das Programm anhalten.

Viel Spass
Uwe
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads