2016-09-25 8 views
-2

ENGR200クラスのエンジニアリングタイプのプログラムを作成しています。以前はプログラミング言語を使ったことは一度もありませんでしたが、ループのあらゆるバリエーションをテストして、最後の3時間ウェブを精査しました。何も動かないようです。条件が満たされたときにループが継続する

それは、私はそれがエラーメッセージ を送信したくない場合は、それは許容範囲内

  • をあるならば私はプログラムがやりたいことは

    1. は、ユーザーの入力
    2. テストを受けています
    3. 新しいエントリを入力する
    4. 許容範囲を満たしていれば残りの部分を続けたい

    私の現在のコードは以下の通りです:

    /******************************************************************************* 
    AUTHOR SECTION 
    
        ENGR 200.xx            DATE: mm/dd/yyyy 
    
        PROGRAM: #        Author: 
    ******************************************************************************** 
    PROGRAM DESCRIPTION 
    
        This program will allow the user to enter the temperature in fahrenheit 
        and relative humidity in percent. Then ask the user wether he/she will be in 
        direct sun. Next, if an unacceptable temp or relative humidiy is entered, an 
        error message should be printed. If the error check is passed, the program 
        will then calculate the heat index and humidex. The program will then print 
        these values temp in degrees fahrenheit, the temperature in degree celsius, 
        the relative humidity, the heat index, and the humidex. Based on the heat 
        index value the program will prin and appropriate warning below the output. 
        If heat index is below 80F print "No health concerns expected." 
    
    
    DESCRIPTION OF VARIABLES 
    NAME   TYPE    DESCRIPTION 
    heat_index  double    Calculated value for heat index 
    humi_index  double    Calculated value for humidex 
    humi_f   double    Calculated variable used in humi_index 
    temp   int     User input for degrees fahrenheit 
    temp_c   double    Calculated value for conversion f --> C 
    relat_humid  int     User input of relative humidity in % [0-100] 
    humi_pow  double    power value for humi_f calculation 
    direct_sun  char    User input for direct sun contact or not 
    heat_index_y double    heat_index + 15 
    humi_index_y double    humi_index + 9 
    
    
    ----------------------------------------------------------------------------- 
    FORMULAS 
    
    humi_pow = (((7.5)*(temp_c))/((237.7)+(temp_c))) 
    
    
    heat_index = 
    (-42.379)+(2.04901523*temp)+ 
    (10.14333127*relat_humid)- 
    (0.22475541*temp*relat_humid)- 
    ((6.83783*(pow(10,-3)))*(pow(temp),2))- 
    ((5.481717*(pow(10,-2)))*(pow(relat_humid,2)))+ 
    ((1.22874)*(pow(10,-3))*(pow(temp,2))*(relat_humid))+ 
    ((8.5282)*(pow(10,-4))*(temp)*(pow(relat_humid,2)))- 
    ((1.99*(pow(10,-6))*(pow(temp,2))*(pow(relat_humid,2))) 
    
    humi_f = 
    ((6.112)*(pow(10,humi_pow)))*((relat_humid)/100.0) 
    
    humi_index = 
    (temp_c+((5.0/9.0)*(humi_f-10))) 
    
    
    *******************************************************************************/ 
    
    /* Preprocessor directives */ 
    #include <stdio.h> 
    #include <math.h> 
    
    /* Main function */ 
    int main() 
    { 
        /* Declare variables */ 
        char direct_sun; 
        double heat_index, humi_index, temp_c, humi_pow, humi_f, humi_index_y, 
        heat_index_y, temp, relat_humid; 
    
        /* Print headings */ 
        printf("********************************************"); 
        printf("\n   APPARENT HEAT CALCULATION"); 
    
        /* Input values */ 
        printf("\n\nEnter temperature in degrees Fahrenheit: "); 
        scanf("%d",&temp); 
        /* Check valididty of temp */ 
        while(temp < 67) 
        { 
        printf("You must input a value greater than 67 degrees fahrenheit."); 
        printf("\nEnter temperature in degrees Fahrenheit: "); 
        scanf("%d",&temp); 
    
        if(temp >= 67) 
        { 
         break; 
        } 
        } 
    
        printf("Enter relative humidity (56% as 56)  : "); 
        scanf("%d",&relat_humid); 
        /* Check validity of relat_humid */ 
        while(relat_humid <= 0 || relat_humid >= 100) 
        { 
        printf("You must input a value between 0 and 100."); 
        printf("\nEnter relative humidity (56% as 56)  :"); 
        scanf("%d",&relat_humid); 
    
        if(relat_humid <= 100 && relat_humid >= 0) 
        { 
         break; 
        } 
        } 
        printf("Working in direct sun (y/n)?    : "); 
        scanf("%c",&direct_sun); 
    
        /* Compute */ 
        temp_c = ((5.0/9.0)*(temp-32)); 
        humi_pow = (((7.5)*(temp_c))/((237.7)+(temp_c))); 
        humi_f = ((6.112)*(pow(10,humi_pow)))*((relat_humid)/100.0); 
        humi_index = (temp_c+((5.0/9.0)*(humi_f-10))); 
        heat_index = 
        (-42.379)+(2.04901523*temp)+ 
        (10.14333127*relat_humid)- 
        (0.22475541*temp*relat_humid)- 
        ((6.83783*(pow(10,-3)))*(pow(temp,2)))- 
        ((5.481717*(pow(10,-2)))*(pow(relat_humid,2)))+ 
        ((1.22874)*(pow(10,-3))*(pow(temp,2))*(relat_humid))+ 
        ((8.5282)*(pow(10,-4))*(temp)*(pow(relat_humid,2)))- 
        (1.99*(pow(10,-6))*(pow(temp,2))*(pow(relat_humid,2))); 
        heat_index_y = heat_index + 15; 
        humi_index_y = humi_index + 9; 
    
        /* Print output values */ 
        printf("\n\nRESULTS"); 
        printf("\nTemperature (degrees F):"); 
        printf("\nTemperature (degrees C):"); 
        printf("\nRelative Humidity:"); 
        printf("\n\nHeat index:"); 
        printf("Humidex:"); 
        printf("WARNING: IF STATEMENT REQUIRED"); 
        printf("\n********************************************\n\n\n"); 
    
        /* Exit the program */ 
        return 0; 
    } 
    /*********************************************************************/ 
    
  • +3

    問題が何ですか。 – immibis

    +3

    「temp」はどこに定義されていますか?そのタイプは何ですか? – user2357112

    +3

    あなたが観察した行動を説明し、それが期待したものとどのように異なるかを説明してください。 –

    答えて

    0

    以下はあなたが必要なものを行う可能性があります:scanf()の戻り結果のテストは本当に悪い入力から保護

    #include <stdio.h> 
    
    #define CUTOFF (67) 
    
    int main() { 
        int temperature = 0; 
        int scanf_result = 0; 
    
        do { 
         /* Input values */ 
    
         printf("Enter temperature in degrees Fahrenheit: "); 
         scanf_result = scanf("%d", &temperature); 
    
         fpurge(stdin); // clear out excess or non-numeric input 
    
         /* Check validity of temperature */ 
    
         if (scanf_result == 0 || temperature < CUTOFF) { 
          fprintf(stderr, "You must input a value greater than %d degrees fahrenheit.\n", CUTOFF); 
         } 
    
         } while (temperature < CUTOFF && scanf_result != EOF); 
    
        if (scanf_result == EOF) { // try to handle user typing ^D aka EOT 
         fprintf(stderr, "Program terminated by user.\n"); 
         return 1; 
        } 
    
        /* now do something useful with temperature */ 
    
        return 0; 
    } 
    

    > ./a.out 
    Enter temperature in degrees Fahrenheit: dog 
    You must input a value greater than 67 degrees fahrenheit. 
    Enter temperature in degrees Fahrenheit: 34 
    You must input a value greater than 67 degrees fahrenheit. 
    Enter temperature in degrees Fahrenheit: 103 
    > 
    
    関連する問題