-
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.
-
Can we see you code so far :)
-
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.
-
I think that the OP wants a simple scanf/printf program to learn how to implement flow chart logic into C code.
-
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.");
}
}
-
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.
-
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.
-
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'
-
perfect, thanks a lot guys. that was much simpler than i'd expected.