사용자에게 인쇄하려는 사각형의 행과 열 수와 원하는 기호를 입력하도록 요청했습니다. 나는 이것을하는 방법에 대해 알지 못하며 모든 Google 검색은 한 행을 인쇄하는 한 나를 얻었습니다. 방향은 행이 3이어야하고 열이 '$'문자가있는 7이어야한다고 지시합니다. 나는 아직 초심자라서 편하게 해주세요. 이것이 내가 가진 것입니다.
#include <iostream>
#include <iomanip>
using namespace std;
void PrintChar(int row = 5, int column = 10, char symbol = '*');
int main()
{
int rows, columns;
char symbol;
cout << "How many rows and columns do you want, and with what symbol (default is *) ?" << endl;
cin >> rows >> columns >> symbol;
PrintChar(rows, columns, symbol);
}
void PrintChar(int row, int column, char symbol)
{
for (int y = 1; y <= column; y++)
{
cout << symbol;
}
그것은 상징의 전체 라인을 인쇄하고 그것이 내 생각이 멈추는 곳입니다. 마지막 행을 도와 주시면 대단히 감사하겠습니다.
이것은 트릭을 할 것입니다. 직사각형처럼 보이도록 줄 바꿈을 추가했습니다.
#include <iostream>
#include <iomanip>
using namespace std;
void PrintChar(int row = 5, int column = 10, char symbol = '*');
int main() {
int rows, columns;
char symbol;
cout << "How many rows and columns do you want, and with what symbol (default is *) ?" << endl;
cin >> rows >> columns >> symbol;
PrintChar(rows, columns, symbol);
return(0);
}
void PrintChar(int row, int column, char symbol) {
for (int y = 1; y <= column; y++) {
for (int x = 1; x <= row; x++) {
cout << symbol;
}
cout << endl;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다