2016-06-29 8 views
-2

したがって、プログラムは、ユーザーが指定した初期温度から温度を計算し、その後、風、湿度、および条件に基づいて変更します。風速の入力、湿度の入力、条件の入力、現在の温度の表示、最初の温度が変更された後の最後の1000の温度の表示、および合計の表示からなる選択肢のメニューを表示するすべての温度のwhileループの配列に値を格納する

私はそのほとんどを行っていますが、最後の1000の温度を保存して表示する方法に問題があります。私はこのプログラムで配列を使用するはずですが、私は必要なものを得るためにどのように使用するのか分かりません。助けてください。

#define _CRT_SECURE_NO_WARNINGS 
#define CLS system("cls") 
#define PAUSE system("pause") 
#include <stdio.h> 
#include <stdlib.h> 

// PROTOTYPING FUNCTIONS 
void askTemp(); 
float convertC(float f); 
void displayMenu(); 
char getChoice(); 
char getCondChoice(); 
float getHumid(); 
float getTemp(); 
float getWind(); 

main() { 
    // INITIALIZE VARIABLES 
    float temp; 
    float wind = 5; 
    float humid = 20; 
    int trump = 0; 
    char choice = 'A'; 
    int num; 
    char cond = 'S'; 
    char condChoice; 
    float celsius; 
    int i = 0; 
    int j = 0; 
    int k = 0; 
    float temp2 = 0; 
    float wind2 = 0; 
    float humid2 = 0; 
    int x = 0; 

    askTemp(); 
    temp = getTemp(); 

    do{ 
     displayMenu(); 
     choice = getChoice(); 

     switch (choice){ 
     case 'W': // Get Wind 
      wind = getWind(); 
      break; 
     case 'H': // Get the humidity 
      humid = getHumid(); 
      break; 
     case 'C': // Enter subswitch statement to get condition 
      condChoice = getCondChoice(); 
      switch (condChoice){ // gets condition 
      case 'S': 
       cond = 'S'; 
       break; 
      case 'C': 
       cond = 'C'; 
       break; 
      case 'R': 
       cond = 'R'; 
       break; 
      }// END SWITCH 
     case 'T': // display current temperature 

      if (temp != temp2 || wind != wind2 || humid != humid2){ // apply degree changes based on humid, wind, and cond 
       if (wind > 100) 
        temp = temp - (temp * .03); 
       if (wind < 10) 
        temp = temp + (temp * .025); 
       if (humid > 75) 
        temp = temp + (temp * .058933); 
       if (humid < 20) 
        temp = temp - (temp * .0162); 
       if (cond == 'S' && wind > 30) 
        temp = temp + (temp * .01); 
       if (cond == 'S' && wind == 0) 
        temp = temp + (temp * .005); 
       if (cond == 'R') 
        temp = temp - (temp * .02); 
       if (cond == 'C' && humid > 75) 
        temp = temp + (temp * .01); 
       if (cond == 'C' && humid < 75) 
        temp = temp + (temp * .005); 
       if (wind > 30 && humid > 75 && cond == 'S') 
        temp = temp; 
       wind2 = wind;  // assigned variables so program does not apply condition changes multiple times for same temp 
       humid2 = humid; 
       temp2 = temp; 
      }// END IF 
     celsius = convertC(temp2); 
     printf("The Current temperature is %.1ff/%.1fc degrees Celsius\n", temp2, celsius); 
     PAUSE; 
     break; 
    case 'P': // Display previous 1000 temperatures 

     break; 
    case 'A': // Display average of all temps entered 
     break; 
    }// END SWITCH 

} while (choice != 'Q'); 



} // END MAIN 

void askTemp(){ 
    printf("What is the current temperature: \n"); 
    return; 
}// end askTemp 

void displayMenu(){ 
    CLS; 
    printf("W. Enter Wind Speed\n"); 
    printf("H. Enter Humidity\n"); 
    printf("C. conditions\n"); 
    printf("T. Current Temperature\n"); 
    printf("P. Previous Temps\n"); 
    printf("A. Average Temperature\n"); 
    printf("Q. Quit\n"); 
    return; 
} // end currentTemp 

char getChoice(){ 
    char result; 
    scanf("%c", &result); 
    result = toupper(result); 
    return result; 
}// end getChoice 

char getCond(){ 
    char result; 


}// end getCond 

char getCondChoice(){ 
    char result; 
    printf("S for sunny, C for cloudy, R for rainy\n"); 
    scanf(" %c", &result); 
    result = toupper(result); 
    do{ 
     if (result != 'S' && result != 'C' && result != 'R'){ 
      printf("Invalid input try again\n"); 
      scanf(" %c", &result); 
      result = toupper(result); 
     } 
    } while (result != 'S' && result != 'C' && result != 'R'); 
    return result; 
}// end getCond 

float getHumid(){ 
    float result; 
    scanf("%f", &result); 
    return result; 
}// end getHumid 

float getTemp(){ 
    float result; 
    scanf("%f", &result); 
    do{ 

     if (result < -50 || result > 150){ 
      printf("Invalid temperature try again\n"); 
      scanf("%f", &result); 
     } 
    } while (result < -50 || result > 150); 
    return result; 
}// end getTemp 

float getWind(){ 
    float result; 
    scanf("%f", &result); 
    return result; 
}// end getWind 

float convertC(float f){ 
    float t; 
    t = (f - 32)/1.8; 
    return(t); 
}// end convert 
+0

「convertC()」以外のすべての「プロトタイプ」は単なる関数宣言であり、プロトタイプではないことに注意してください。彼らは、フィクションは存在するが、引数リストについては何も言わない(変数リストではないことを除いて)。プロトタイプを作るためには、括弧の中に 'void'を入れる必要があります:' void askTemp(void); 'など –

答えて

0

あなたはこのような1000年floatの配列を宣言:

float saved_temperatures[1000]; 

あなたは、配列にインデックスを付けると、変数のようにそれを使用することにより、それに値を格納します。

saved_temperatures[i] = temp; 
++i; 

iインデックス変数であり、あなたはそれがsaved_temperaturesのための有効なインデックスの範囲は、0..999でゼロから始まり、常に1000未満であることを確認しなければなりません。

for (int i = 0; i < 1000; ++i) { 
    printf("index %d temperature %f\n", i, saved_temperatures[i]); 
} 
関連する問題