Thread: I needs help on writing a C Program that keeps track of the total amount of pulse a m

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Smile I needs help on writing a C Program that keeps track of the total amount of pulse a m

    I needs help on writing a C Program that keeps track of the total amount of pulse a meter goes high. When the pulse goes high the count should start.
    Pulse = 0 = P when pulse goes high value changes to 1
    At first K=P then when another pulse comes in K=1 with the first pulse. The when the second pulse goes high P =1 and the following formula would be used to finr the new total amount of pulses.
    K = K + P (2 = 1 + 1)
    Now K = 2 this is now the total amount of pulses
    Another pulse comes in
    K = K + P (3= 2 + 1)
    This should be an infinite loop.
    Then I would compare K to another value R (R is another pulse that will go high) If the value of R goes high it will save the value of K and keep record of the final pulse. But the pulse count should not stop.
    If( R =1;
    K= total pulse
    Else continue)
    Please help me. I have the idea but I’m not 100 percent sure if this will work.

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Can you show what you've done so far?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I have the idea but I’m not 100 percent sure if this will work.
    Good - so try it then.

    Even if it doesn't work, you'll learn something.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    What I have so far

    {
    int pulse = 0;
    int total_pulse =0;
    int result = 0;

    do { if pulse == 1;
    total_pulse=total_pulse +1;

    if{result == 1
    result = total_pulse
    printf("the total pulse is %d \n", total_pulse);

    else

    continue;


    But this would end the loop if result equals to 1. How can I make it total_pulse formual keep tracking the number of pulse.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by peque85 View Post
    But this would end the loop if result equals to 1.
    If? Or does?? As Salem wrote, you need to actually try, and in the process you will gain insight that just sitting there thinking will not provide.

    For example, from my perspective, this is not a loop, nor does it make much sense. You have three opening opening braces and not a single closing one.

    So, if you write some code that actually compiles and runs without error -- even if at first it does not meet your goals -- you will at least have a realistic starting point, since if your code does not compile and run without error, it is almost ridiculous to discuss what the code does or does not do...it doesn't do anything, the compiler (and other programmers) are just going to perceive it as nonsensical.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems installing Mingw5.1.4
    By BlackOps in forum C Programming
    Replies: 2
    Last Post: 07-26-2009, 03:28 AM
  2. Trying to convert a total amount into change
    By American Raptor in forum C Programming
    Replies: 9
    Last Post: 12-07-2008, 10:33 PM
  3. Determing the amount of change(money)
    By Kyeong in forum C Programming
    Replies: 11
    Last Post: 09-30-2008, 04:36 PM
  4. Help with a file writing program
    By pritesh in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 01:56 AM