2017-11-11 88 views
-1

我想打印索引表,就像我在這裏的索引表 但它沒有正確排列。我想我錯過了一個結局; 預先感謝您。他們不會讓我發佈這個問題沒有更多的上下文,所以我打字這看看這是否可能工作。我的索引表沒有排隊

#include <iostream> 
#include <cmath> 
#include <iomanip> 
using namespace std; 

int main() 
{ 


cout << "Wind Chill Table" << endl;   //Produces the table 
cout << "Speed Temperature T " << endl; //Produces the table 
cout << "MPH";        //Produces the table 



for (int temp = 45; temp >= -10; temp -= 5) // Generate temp 45 to -10 
{ 
cout << setw(5)<< temp ; 
} 

cout << endl; 


for (int count = 0; count <= 62; count++) // generate the lines "------" 
{ 
cout << "-" ; 
} 
cout << endl; 

for(int speed = 5; speed <=50; speed+=5) // generate the speed 5 to 50 
{ 
cout << setw(5)<< speed <<"|" << endl; 
for (int temp = 45; temp >=-10; temp -= 5) 
{ 

cout << setw(5)<<windchill(speed,temp);// calling the function windchill 
} 
cout << endl; 
} 

return 0; 
} 




int windchill(int s, int t)// function to calculate the wind chill 
{ 

int windChillFactor = int(round(35.74 + 0.6215 * 
t - 35.75 * pow(s, 0.15) + 
0.4275 * t * pow(s, 0.16))); //Formula for wind chill 

return windChillFactor; 

} 

回答

0

這個怎麼樣?

int main() 
{ 


    cout << "Wind Chill Table" << endl;   //Produces the table 
    cout << "Speed Temperature T " << endl; //Produces the table 
    cout << "MPH"<< endl;      //Produces the table 



    cout << setw(6) <<" "; /*!!! change !!!*/ 
    for (int temp = 45; temp >= -10; temp -= 5) // Generate temp 45 to -10 
    { 
     cout << setw(5)<< temp ; 
    } 

    cout << endl; 


    for (int count = 0; count <= 62; count++) // generate the lines "------" 
    { 
     cout << "-" ; 
    } 
    cout << endl; 

    for(int speed = 5; speed <=50; speed+=5) // generate the speed 5 to 50 
    { 
     cout << setw(5)<< speed <<"|" /*<< endl*/; /*!!! change !!!*/ 
     for (int temp = 45; temp >=-10; temp -= 5) 
     { 
      cout << setw(5)<<windchill(speed,temp);// calling the function windchill 
     } 
     cout << endl; 
    } 

    return 0; 
} 

結果:

Wind Chill Table 
Speed Temperature T 
MPH 
     45 40 35 30 25 20 15 10 5 0 -5 -10 
--------------------------------------------------------------- 
    5| 43 37 31 25 20 14 8 2 -4 -10 -16 -22 
    10| 41 35 29 22 16 10 4 -2 -9 -15 -21 -27 
    15| 40 33 27 21 14 8 1 -5 -12 -18 -24 -31 
    20| 39 32 26 19 13 6 -1 -7 -14 -20 -27 -33 
    25| 38 31 25 18 11 5 -2 -9 -16 -22 -29 -36 
    30| 37 31 24 17 10 3 -3 -10 -17 -24 -31 -37 
    35| 37 30 23 16 9 2 -5 -11 -18 -25 -32 -39 
    40| 36 29 22 15 8 1 -6 -13 -19 -26 -33 -40 
    45| 36 29 22 15 8 1 -6 -13 -21 -28 -35 -42 
    50| 35 28 21 14 7 0 -7 -14 -21 -29 -36 -43