所以我遇到了另一个问题。我一直试图解决这个问题大约一个小时,但没有运气。我无法让这个嵌套的 while 循环工作。代码应该根据输入放入行中,但目前它会一直持续下去。
#include <iostream>
using namespace std;
void PrintLines(char characterValue, int characterCount, int lineCount);
// I'm going to have to change char characterValue to int characterValue
// will this still work if they are in seperate files?
void PrintLines(char characterValue, int characterCount, int lineCount)
{
while (lineCount--) //This is the problem
{
while (characterCount--)
{
cout << characterValue;
}
cout << "\n";
}
}
int main()
{
char Letter;
int Times;
int Lines;
cout << "Enter a capital letter: ";
cin >> Letter;
cout << "\nEnter the number of times the letter should be repeated: ";
cin >> Times;
cout << "\nEnter the number of Lines: ";
cin >> Lines;
PrintLines(Letter, Times, Lines);
return 0;
当我这样做以检查它是否正常工作时。我看到它确实...
while (lineCount--) //This is to check
cout << "\n%%%";
{
while (characterCount--)
{
cout << characterValue;
}
}
它打印 :(如果 Lines = 4 and Times = 3 and Letter = A)
%%%
%%%
%%%
%%%AAA