我的索引表没有排队

时间:2017-11-11 04:46:16

标签: c++

  

我想打印索引表,就像我在这里一样       但它没有正确排队。我想我错过了一个endl;       先感谢您。他们不会让我在没有更多背景的情况下发布这个问题所以我输入这个以确定这是否可行。

#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;

}

1 个答案:

答案 0 :(得分: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