打印表格C++



我正在尝试打印一个如下所示的表:

                       Number of Queues
 Oc           2               3             4              5
50,000   average-max    average-max    average-max   average-max
100,000  average-max    average-max    average-max   average-max
150,000  average-max    average-max    average-max   average-max

等等

其中average是getAverage((,max是getMax((。

amount包含阶跃Oc值。

我一直试图使用的代码如下:

cout << setw(5) << "Oc" << setw(10) << "2" << setw(5) << "3" << setw(5) << "4" << setw(5) << "5" << endl << endl;
while (amount < 400000)
{
        amount += 50000;
        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);
            simulator.start();
            cout << setw(5) << amount << setw(10) << simulator.getAverage() << "-" << simulator.getMax();
        } //end for loop
} //end while loop

我需要一些帮助来修复这个问题,以便正确地显示桌子,它现在到处都是。

while (amount < 400000)
{
        amount += 50000;
        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);
            simulator.start();
            cout << setw(5) << amount << setw(10) << simulator.getAverage() << "-" << simulator.getMax() << "t";
        } //end for loop
} //end while loop

您可以使用"\t">

cout << setw(6) << "Oc" << setw(10) << "2" << setw(10) << "3" << setw(10) << "4" << setw(10) << "5" << endl << endl;
while (amount < 400000)
{
        amount += 50000;
        cout << setw(5) << amount;
        for (int i = 2; i <= 5; i++)    //2 and 5 for the number of queues
        {   
            Simulator simulator(i, amount);
            simulator.start();
             cout << setw(10) << simulator.getAverage() << "-" << simulator.getMax();
        } //end for loop
        cout << endl;   
} //end while loop

祝好运

相关内容

  • 没有找到相关文章

最新更新