这是我为 compsci 分配的任务,我被困在如何让星域“*”重复用户想要多少次的最后。
编写一个程序,打印出一系列星域(即“*”)。每个字段将有 n 行和 m 列。允许用户输入行数(至少 1 但不超过 5)和列数(至少 5 但不超过 50)以及字段数(至少 3 但不超过 10) . 每个字段必须由 3 个完整的空白行分隔。
您的程序必须至少包含两个功能:一个从用户那里获取输入数据,另一个用于绘制每个字段。使用 for 循环来构造字段,以及打印出多个字段。不要使用字符串“<em>”。而是打印出单个“</em>”。
代码
#include <iostream>
using namespace std;
void displayField(int numrows, int numcolums);
void getData (int numrows, int numcolumns, int numfields);
const char c = '*';
int main(void)
{
int numrows, numcolumns, numfields;
cout << "Welcome to the banner creation program!" << endl;
cout << "Enter the number of rows (1 - 5) --> ";
cin >> numrows;
if(numrows<1 || numrows>5){
cout << "Your entered value is outside the range!" << endl;
cout << "Program will now halt..." << endl;
exit(0);}
cout << "Enter the number of columns (5 - 50) --> ";
cin >> numcolumns;
if(numcolumns<5 || numcolumns>50){
cout << "Your entered value is outside the range!" << endl;
cout << "Program will now halt..." << endl;
exit(0);
}
cout << "Enter the number of rows (3 - 10) --> ";
cin >> numfields;
if(numfields<3 || numrows>10){
cout << "Your entered value is outside the range!" << endl;
cout << "Program will now halt..." << endl;
exit(0);
}
for(int i=1; i<=numrows; i++){
for (int j=1; j<=numcolumns; j++)
cout << c;
cout <<endl;
}
}