我被告知要求用户输入他们想要打印的矩形的行数和列数以及他们想要的符号。我不知道如何做到这一点,我所有的谷歌搜索只让我打印一行。方向指示行应为 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;
}
}
我是一名优秀的程序员,十分优秀!