不知道如何启动此程序 - 使用循环生成条形图

时间:2014-04-02 00:02:54

标签: c++

通常我不会这样做,但我需要一些重要的帮助。我甚至不知道从哪里开始使用此代码。它应该有一个输出:

What is the production of Plant 1 (000's)? 6
What is the production of Plant 2 (000's)? 4

                             PRODUCTION (000'S)
                    0   1   2   3   4   5   6   7   8
                    |---|---|---|---|---|---|---|---|
        Plant 1     *************************
        Plant 2     *****************

我知道要求别人提供这么多的帮助并不是一个好习惯,但是我的斗智斗勇并且已经碰壁了。任何帮助将不胜感激

这就是我所拥有的,我知道这是错误的,可能甚至没有关闭

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

int main()

{

cout<<"What is the production of Plant 1 (000's)? ";
int plant1;
cin>>plant1;
cout<<"What is the production of Plant 1 (000's)? ";
int plant2;
cin>>plant2;
cout<<"                      PRODUCTION (000's)"<<endl;;
cout<<"              0   1   2   3   4   5   6   7   8"<<endl;
cout<<"              |---|---|---|---|---|---|---|---|"<<endl;
cout<<"Plant 1";


for (int i=0; i<=plant1; i++)
{   
    cout<<"*";
}
cout<<"Plant 2";
    for (int j=0; j<=plant2; j++)
    {
    cout<<"*";
    }

cout<<endl;
return 0;
}

1 个答案:

答案 0 :(得分:0)

试试这个:

cout<<"Plant 1";

for( int i = 0 i < 6 ; i++) cout<<" ";
for (int i=0; i<=plant1; i++)
{   
    cout<<"*";
}
cout<<endl<<"Plant 2";
for( int i = 0 i < 6 ; i++) cout<<" ";
    for (int j=0; j<=plant2; j++)
    {
    cout<<"*";
    }

cout<<endl;

其余部分保持不变。