2016-09-20 7 views
0

私はC++には新しく、forループを使用してテーブルを作成しています。C++でテーブルを作成しようとしましたが、問題がありました。

私はすべて一つのループで開始列、行、およびcalcWind値を持つforループのために問題を抱えてきました。そこで私は2つの部分に分解することに決めました。

最初のforループは、行のすべての開始値を配置します。次のforループは列の値を配置し、風の速度を計算するために作成した関数に行#と行#を挿入します。

私は今、コンソール画面上の実際の計算を示すために、Calcwindのためのトラブルを抱えています。事前に助けを再び

感謝:)ここ

Here's what the console image should look like, I'm just laying down the values with my code for now.

#include <iostream> 
#include <iomanip> 
#include <cmath> 
#include <cmath> 

using namespace std; 

double calcWind(double temperature, double windSpeed) 
{ 
    double wind = 0; 
    wind = 35.74 + (.621 * temperature) - (35.75 * pow(windSpeed, 0.16)) + (.4275 * temperature * pow(windSpeed, .16)); 
    wind = nearbyint(wind); 
    return wind; 
} 

int main() 
{ 
    int rows = 40; 
    int columns = 5; 

    for (rows; rows >= -30; rows = rows - 5) 
    { 
     cout << setw(6) << rows; 
    } 

    for (columns; columns <= 60; columns = columns + 5) 
    { 
     cout << endl << columns; 
     for (rows; rows >= -30; rows = rows - 5) 
     { 
      cout << setw(6) << calcWind(rows, columns); 
     } 
    } 


    system("pause"); 
    return 0; 
} 
+0

'std :: system(" pause ");'はかなり危険です。 – CoffeeandCode

+0

最初のループの後に、あなたの変数 'rows'は既に' -30'に等しくなります。 – GAVD

+0

あなたの_ "トラブル" _を詳しく教えてください。それはかなり曖昧です。 –

答えて

0

あなたがrowsを作成します。

int rows = 40; 

それは-30の下になるまであなたは、その後(5を引いておきます最初のループ):

for (rows; rows >= -30; rows = rows - 5) 

その後、calcWindの出力を印刷するループでは、rowsは-35と同じです。条件rows >= -30は最初の反復で失敗し、calcWindを実行したり、結果を出力したりしません。

0

これを試すことができます。

#include <iostream> 
#include <iomanip> 
#include <cmath> 
#include <math.h> 
#include <stdio.h> 

using namespace std; 

double calcWind(double temperature, double windSpeed) 
{ 
    double wind = 0; 
    wind = 35.74 + (.621 * temperature) - (35.75 * pow(windSpeed, 0.16)) + (.4275 * temperature * pow(windSpeed, .16)); 
    wind = nearbyint(wind); 
    return wind; 
} 

int main() 
{ 
// int rows = 40; 
// int columns = 5; 

    for (int rows = 40; rows >= -30; rows = rows - 5) 
    { 
     cout << setw(6) << rows; 
    } 

    for (int columns = 5; columns <= 60; columns = columns + 5) 
    { 
     cout << endl << columns; 
     for (int rows = 40; rows >= -30; rows = rows - 5) 
     { 
      cout << setw(6) << calcWind(rows, columns); 
     } 
    } 

    std::cout << "\nPress any key to continue. . .\n"; 
    cin.get(); 
    return 0; 
} 
関連する問題