Computer Science Canada

Counter in C

Author:  guopeter [ Mon Feb 04, 2008 1:53 pm ]
Post subject:  Counter in C

Hi, I'm having difficulty programming a switch counter.

Basically what I need is a program that adds 1 to the variable every time a switch goes from 1 to 0 and 0 to 1.

Now it's getting frustrating..
So if anyone can help that'll be greatly appreciated!!!
THANKS!!!

Author:  md [ Mon Feb 04, 2008 5:27 pm ]
Post subject:  RE:Counter in C

C:

int count = 0;
int flip = 0, old_flip=0;
while(true)
{
    if( flip != old_flip )
    {
        count++;
        old_flip = flip;
    }
}


Is that what you mean? Clearly something would have to be added to cause flip to change in my example... I didn't write that Razz

Author:  Parliam [ Wed May 28, 2008 11:11 am ]
Post subject:  Re: Counter in C

int count=0;
int variable_number=0;
for(i=0;i<variable_number;i++)
{
variable_number=i;
count+=1;

}


the program's have express your means ??

Author:  md [ Thu May 29, 2008 8:51 pm ]
Post subject:  RE:Counter in C

Parliam, this thread is kinda old and we frown on reviving old threads.

Also, your code does not work; give it a try in a debugger and you'll see why Wink

Author:  Parliam [ Tue Jun 03, 2008 5:59 am ]
Post subject:  RE:Counter in C

okay,i have seen the results,thz!!


: