이것은 compsci와 im에 대한 나의 임무이며, 별표 필드를 얻는 방법의 맨 끝에 '*'가 반복되어 사용자가 원하는 것을 반복합니다.필드 자체를 반복합니까?
일련의 별표 (즉, "*")를 인쇄하는 프로그램을 작성하십시오. 각 필드에는 n 개의 행과 m 개의 열이 있습니다. 사용자가 필드 수 (최소 3, 최대 10)와 행 수 (최소 1에서 최대 5)와 열 (최소 5에서 최대 50)을 입력 할 수있게하십시오. . 각 필드는 3 개의 완전한 빈 줄로 구분해야합니다.
프로그램에는 최소한 사용자의 입력 데이터를 가져 오는 기능과 각 필드를 그리는 기능이라는 두 가지 기능이 있어야합니다. 루프를 사용하여 필드를 구성하고 여러 필드를 인쇄하십시오. ""문자열을 사용하지 마십시오. 오히려 개인 ""을 인쇄하십시오.
코드
#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;
}
}
무엇이 오류입니까? –
오류는 없지만 필드 자체를 반복하는 방법을 이해하지 못합니다. –
* Aside * :'\ n '을 의미 할 때'endl'을 사용하지 마십시오. 귀하의 프로그램에서 그들은 동등합니다; 다른 프로그램에서는'endl'은 프로그램이 느리게 실행되도록합니다. –