简体   繁体   中英

How to turn this Flow chart into “workable” code in C?

Let me begin by saying I have no idea what I'm doing with code. The most I can do is make an LED blink on an Arduino... And even then, I'm a cheater by uploading the pre-installed sketch and edit variables to make the light blink faster or slower... Nothing more. I've done multiple searches to find something understandable and coherent (in my mind being a non coder) but I can't find anything that matches my needs.

With the above said, I have included a flow chart that details how I want my code to work AS IF it were real code to make something work... For example, when an input is sensed (the diamonds), the code prints words (output). How would I write this code in C? (sorry for horrible tagging, I couldn't figure out anything that would pop up other than the one you see).

The purpose of this is to write the code on paper for a cute love note to my wife.

在此处输入图像描述

The purpose of this is to write the code on paper for a cute love note to my wife.

I think you have done this already. Your flowchart is much more charming than any C code could ever be.

My only worry is the "do nothing" boxes. You might want to seek feedback on that from your end user, and revise the logic as needed.

This will help teach you the art of debugging, a skill you will need for every programming language you ever use.

In fact I suggest working through the entire chart with her. You never know what might happen!

And you won't need a single line of C code to do it.

One more thing... Keep the old versions of the chart if you revise it. This way you will learn about version control, and you will have a fun story to share with your grandchildren.

OK, I'll play this silly game and make like some nerdy Cyrano de Bergerac!

Your flow chart does not really work - you have some "do nothing forever" dead ends - which seems rather tragic. I have interpreted this to mean rather "do nothing until..:" which would look like:

在此处输入图像描述

which may be visually less attractive, but at least does not speak of the death of your marriage!

That being the case then:

#include <stdio.h>
#include <letter.h>
#include <wife.h>
#include <love.h>

int main()
{
    while( !letterOpen() ) { }

    printf( "Dear honey,\n\n" ) ;
    while( !wifeSmiling( ANY ) ){ }

    printf( "I just wanted to say\n" ) ;
    while( !wifeSmiling( TEARS_OF_JOY ) ){ }

    printf( "I love you\n" ) ;
    while( !wifeSmiling( TEARS_OF_JOY ) ){ }

    printf( "\nLove your loving husband\n" ) ;
    while( !wifeSmiling( TEARS_OF_JOY ) ){ }

    doHugs() ;
    doKisses() ;

    return SUCCESS ;
}

Output:

Dear honey,

I just wanted to say
I love you

Love your loving husband

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM