我的任务是编写一个程序来根据用户输入的数据显示一个星域 (*)。我得到了代码,但我的导师要求将它们放在至少两个函数中。显示横幅功能不起作用。getData 运行并要求用户输入值,但随后程序在输入后停止。似乎出了什么问题?
#include <iostream>
using namespace std;
void displaybanner(int numrows=0, int numcolums=0, int numfields=0);
void getData(int numrows=0, int numcolumns=0, int numfields=0);
const char c = '*';
int main(void)
{
getData();
displaybanner();
}
void getData(int numrows,int numcolumns,int 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);
}
}
void displaybanner(int numfields, int numrows, int numcolumns)
{
for (int i = 0; i < numfields; i++) {
for (int j = 0; j < numrows; j++) {
for (int k = 0; k < numcolumns; k++) {
cout << c;
}
cout << endl;
}
cout << endl << endl << endl;
}
}