我写了这段代码,但不知何故,当它要求用户输入一个新的数字来创建一个正方形时,它不打印正方形。任何人都可以解释/帮助我吗?创建空心广场c + +
// ask user to repeat the process again at end of the first promt
while (num > 1 || num < 20)
{
ask user to repeat the process again at end of the first promt
while (num > 1 || num < 20)
{
// ask user t enter a square
cout << "Please enter size of square between #1-20: \n";
cin >> buf; num = atoi (buf.c_str());
cin.ignore(1000, 10);
// process of printing square
while (num >= a)
{
b = 1;
while (num >= b)
{
if (a == 1 || a == num || b == 1 || b == num)
cout << "*";
else
cout << " ";
b++;
}
cout << endl;
a++;
}
请正确格式化您的代码。我似乎注意到你的代码中的一些注释实际上不是'//注释' – Borgleader
猜你在做作业吗?考虑左侧和右侧总是相同的,即左侧为“*”,右侧为“* \ n”。你只需要用正确的字符填充中间,然后为正确的行数做 –
顺便说一句 - 用于循环 –