Thread: Help with flowchart.

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    5

    Help with flowchart.

    Hey all. I'm having some trouble figuring out which methods to use to code this flowchart in C. I'm a total beginner, and really don't know the best way of going about this, but was attempting it with nested if statements. Had some problems getting that to work though.

    Anyways, here's the chart:

    c flowchart | Flickr - Photo Sharing!

    Any help's really appreciated.

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Can we see you code so far
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    The flowchart provided is described as a "Troubleshooting Chart". It does not tell you an algorithm that you could realistically write a C program for. For example, one of the actions says "Refer to inlet service manual". Its not meant for a computer to do these steps.

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I think that the OP wants a simple scanf/printf program to learn how to implement flow chart logic into C code.
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    Click_here's got the idea. Tried to edit this as best I could, probably some errors. I've got to run right now but I'll be back on here asap. Thanks again everyone.

    Code:
    
    
    #include <stdio.h>
    
    
    int main(int argc, const char * argv[])
    
    
    {
        
    
    
    char l;
    int meter3;
    
    
        
        puts("Check status lights. 'r' for red, 'g' for green, and 'a' for amber.");
        scanf("%c", &l);
    
    
        if(l == 'r')
            {
                {
                printf("Shut off all input lines and check meter #3.");
                scanf("%i", &meter3);
                
        
                if(meter3 >=50) 
                    {
                    char pres;
                    printf("Check main line for test pressure. Input 'n' for normal or 'x' for abnormal.");
                    scanf("%c", &pres);
                    
                    if(pres == 'n')
                        printf("input n");
                    
                    else if(pres == 'x')
                        printf("input x");
                    }
                    
                    }
            }
        
     
        if(l == 'g')
            {
                printf("Do restart procedure.");
            }
       
        if(l == 'a')
            {
                printf("Check fuel line service routine.");
            }
        
        
    }

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    Some of the statements were just written so that I could see how it was running and may not make sense with the actual chart. Like "input x" and "input n" after "Check main line for test pressure...", I just wanted to see if my scanf was working. Because at that point the program just ended, and I could not figure out why.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In all your scanf()'s for a single char, add one space before the % - or your input will "skip" over them, unless the input buffer has already been cleared of any trailing newlines, etc..

    So, not
    Code:
    scanf("%c",&yourCharVariable);
    
    //but
    scanf(" %c",&yourCharVariable);  //note the added space - eats the trailing newline left on the input buffer
    The above is only needed for char scanf()'s, not for numbers or strings, which skip over whitespace.

  8. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    On top of Adak's solution, don't forget to put a "return 0" at the end of your main function.

    Also, to get an integer from scanf, use 'd' instead of 'i'
    Fact - Beethoven wrote his first symphony in C

  9. #9
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    perfect, thanks a lot guys. that was much simpler than i'd expected.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. High/Low Flowchart help
    By onyxius in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2012, 03:57 PM
  2. Flowchart help
    By MstrKurt in forum C Programming
    Replies: 8
    Last Post: 01-17-2012, 01:23 AM
  3. Need help with flowchart
    By moey187 in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2011, 04:25 AM
  4. flowchart. Help!!!
    By chema124 in forum C Programming
    Replies: 3
    Last Post: 12-10-2002, 10:00 AM
  5. Flowchart
    By ob1cnobe in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2002, 12:03 PM