cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/11/17:20:43

From: Vic <tudor AT cam DOT org>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: I can't seem to get this to work!
Date: Mon, 11 Jan 1999 15:39:25 -0500
Organization: Communications Accessibles Montreal, Quebec Canada
Lines: 67
Message-ID: <369A617D.7133@cam.org>
References: <3699E931 DOT A63558C6 AT erols DOT com>
NNTP-Posting-Host: dialup-613.hip.cam.org
Mime-Version: 1.0
X-Mailer: Mozilla 3.0Gold (Win95; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Jason Mullins wrote:
> 
> Hello -
>     Im new to programming.  I wondering why I can't get this code to
> count backwards form 6 to 0 and exit.  I will start at 6, and go down to
> negitives (becuase it's a "int").  I was told that it could be done in a
> while loop.  not a do while.  Any suggestions?
> 
> Thanx in advance.
> 
> Jason Mullins

I don't know what you want to do exactely, so I'll correct some things
in your code and write another one that works.
 
> #include <stdio.h>
> 
> int main()
> {
> int count;
> int cycle;
>     cycle = 0;
>     count = 6;
>     while (count <= 6, cycle = 6)
             ^^^^^^^^^^^^^^^^^^^^^
what you are doing here is this:
count will ALLWAYS be <= than 6 because you start at 6 and then
decrease. second, with cycle=6 you ASSIGN 6 to cycle evey loop. I don't
think this is what you want. try cycle <=6 or cycle!=6
        
>     {
>         printf("The value of count is %d\n");
                                      ^^^^^^^^
you must give the variable to be printed here. something like
printf("The value of count is %d\n",count);
EVERYBODY: even though he doesn't put any variable in the code the
program still prints something that appears to be "cycle" (in the
beginning it's just 6, if you modify cycle=6 in the while it will print
something from 0 to 6.) WHY?? 

>         count = count--;
>         cycle = cycle++;

variable-- or variable++ increments it automatically.
you can say var++ or var=var+1, it's the same thing.
that code should be count-- or count=count-1, not count=count--;
the same goes for cycle.

>      }
>      return 0;
> }


a code that works is this:
#include <stdio.h>

int main()
{
int count;
    count = 6;
    while (count>=0)
    {
        printf("The value of count is %d\n",count);
        count--;
     }
     return 0;
}

- Raw text -


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