没有C

时间:2018-08-09 22:07:02

标签: fflush

新手在这里。我一直在做一些练习档案,并试图记住,以便我可以学习逻辑并可以在以后回忆。我下载了一些练习文件,这些文件应该可以正常运行。但是,当我不添加fflush(stdout)代码时,Eclipse CPP Photon会警告“为此处的文件名”没有任何内容。我该如何解决?谢谢。

#include <stdio.h>
#include <stdlib.h>

//Constant definitions to increase code readability
#define SELL_PRICE_POINT 54.2
#define BUY_PRICE_POINT  28.5

//Function prototypes
double askStockValue(void);
void makeDecision(double value);
void handleTransaction(char action);

int main(void) {
    double value = askStockValue();
    makeDecision(value);
    return EXIT_SUCCESS;
}

//---- FUNCTION DEFINITIONS ----

double askStockValue(void){
    printf("What is the current stock value?");
    fflush(stdout);
    double value;
    scanf("%lf",&value);
    return value;
}

void makeDecision(double value){
     /*
     * Nested if-statements are a good choice when
     * choices are within a particular range of values
     */
    if (value <= BUY_PRICE_POINT)
        handleTransaction('b');
    else
        if(value >= SELL_PRICE_POINT)
            handleTransaction('s');
        else
            handleTransaction('h');
}

void handleTransaction(char action){
    /*
     * Switch statements are a good choice when
     * choices are matching exact values
     */
    switch(action){
    case 'b':
        printf("I suggest you buy more of this stock.\n");
        fflush(stdout);
        break;
    case 's':
        printf("I suggest you sell this stock.\n");
        fflush(stdout);
        break;
    case 'h':
        printf("Let's wait and see what the market is doing.\n");
        fflush(stdout);
        break;
    default:
        printf("Sorry, I cannot provide any advice at this time.\n");
        fflush(stdout);
    }
}

0 个答案:

没有答案