简体   繁体   English

如何将此流程图转换为 C 中的“可行”代码?

[英]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.我能做的最多的就是让 Arduino 上的 LED 闪烁......即使这样,我也是一个骗子,上传预装的草图并编辑变量以使灯闪烁得更快或更慢......仅此而已。 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?我将如何在 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.您的流程图比任何 C 代码都更迷人。

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.并且您不需要一行 C 代码来执行此操作。

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!好吧,我会玩这个愚蠢的游戏,让自己像个书呆子 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: Output:

Dear honey,

I just wanted to say
I love you

Love your loving husband

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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