【发布时间】:2016-08-31 03:25:21
【问题描述】:
我正在尝试创建一个将使用一维数组进行绘制的程序,但是我很难仅使用一个 cin 语句来初始化数组。用户应该看起来像的示例输入
1<space>2<space>34<space>3<space>2<space>1<space>0<space>10
#include<iostream>
using namespace std;
/*---------------------------------------------------------------------------------------
Prototypes
These are the prototype function(s) that will be used to to draw the row and columns
---------------------------------------------------------------------------------------*/
void draw(int nums);
//---------------------------------------------------------------------------------------
int main(){
const int MAX = 100;
int chart[MAX];
int nums;
cout << "Enter numbers for the chart" << endl;
cin >> nums;
draw(nums);
return 0;
}
void draw(int nums) {
cout << endl;
int row;
for (row = 0; row < nums; ++row) {
cout << "*" << endl;
}
}
如何使用给定的示例输入初始化数组,然后将其传递给用于绘制的函数
【问题讨论】:
标签: c++ arrays function initialization