almost there.... please help

This is a discussion on almost there.... please help within the C Programming forums, part of the General Programming Boards category; How do I incorporate an if/then into this to print a warning messege when a specified value is reached on ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    7

    almost there.... please help

    How do I incorporate an if/then into this to print a warning messege when a specified value is reached on the potentiometer.

    int ReadPot()
    {

    int i;

    pin = output; pin = l;
    for (i = 0; i < charge; i++);
    pin = input;
    for ( i = 0; pin == l; i++);

    return I ;

    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You should be waterboarded for not properly using code tags.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by TommyBoy View Post
    How do I incorporate an if/then into this to print a warning messege when a specified value is reached on the potentiometer.

    Code:
    int ReadPot()
    {
    
    int i;
    	
    	pin = output; pin = l;
    	for (i = 0; i < charge; i++);
    	pin = input;
    	for ( i = 0; pin == l; i++);
    
    	return I ;
    
    }
    Sorry, that won't compile. You have declared i, but not I, and you have set pin equal to 'l', having never declared it as a variable.

    Please post up the code that you're actually using - we can't give you good advice with this example.

    Code:
    if(vcPot == warningValue)
      ( print your warning message here);
    That's pretty lousy, but it's the best I can do with your example code.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    7

    latest progress

    does this look any better?


    function ReadPot()
    {
    int i;
    i = output;
    for(i;i<=charge;i++){

    if(i>=1290){
    printf("WARNING: MAX VALUE EXCEEDED\n");
    return 0;
    }
    }
    return 0;
    }

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by MacGyver View Post
    You should be waterboarded for not properly using code tags.
    Perhaps you think this is an idle threat.

    << !! Posting Code? Read this First !! >>

    You can combine
    Code:
    int i;
    i = output;
    into "int i = output;". Where is "charge" defined/declared?

    ps. next time hold your breath
    Last edited by MK27; 06-11-2009 at 12:57 PM.
    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

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
    function ReadPot() {
      int i;
      i = output;
      for(i;i<=charge;i++){
    
        if(i>=1290){
          printf("WARNING: MAX VALUE EXCEEDED\n");
          return 0;
        }
      }
      return 0;
    }
    Yes, that does look better - but without knowing all the details of the rest of your code or what problem you're trying to solve - we can't say much more than that. Does it work for you?

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    7
    Code tag box wasn't there, thanks for your concern Ace.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TommyBoy View Post
    Code tag box wasn't there, thanks for your concern Ace.
    Hey Mr. Attentive! I did edit my post to include some useful info, I think. I didn't expect you to be so fast.

    Isn't the potentiometer the main ingredient of the WAH_WAH pedal?

    ps. you are suppose to add the code tag box dufus. It's not hard. Get used to it.
    Last edited by MK27; 06-11-2009 at 01:02 PM.
    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

  9. #9
    Registered User
    Join Date
    Jun 2009
    Posts
    7
    Thanks for your help MK...

  10. #10
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,050
    You might wanna return something other than 0 when max value is exceeded to differentiate a normal return from an abnormal one.

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
      int i;
      i = output;
      for(i;i<=charge;i++){
    Following up on what MK27 said, you can actually combine this all into one line:

    Code:
    for(int i=output;i<charge;i++) {

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by sean
    Code:
    for(int i=output;i<charge;i++) {
    That is contra C99.
    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

  13. #13
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Oh riiight... yes - my bad.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21