これは compsci に対する私の課題であり、星のフィールド '*' をユーザーが望む回数繰り返す方法の最後で立ち往生しています。
一連の星のフィールド (つまり、「*」) を出力するプログラムを作成します。各フィールドには n 行 m 列があります。ユーザーが行数 (1 以上 5 以下) と列数 (5 以上 50 以下)、およびフィールド数 (3 以上 10 以下) を入力できるようにします。 . 各フィールドは、3 つの完全な空白行で区切る必要があります。
プログラムには少なくとも 2 つの関数が含まれている必要があります。1 つはユーザーから入力データを取得する関数で、もう 1 つは各フィールドを描画する関数です。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;
}
}