首先,我是一个初学者,试图弄清楚如何使用星号上下移动打印字母“OK”。目标是从偏移位置开始,并让它们增加和减少 x 次。(我还没有参与这部分)。但首先我坚持为什么'K'没有按照我想要的方式打印出来。任何人都可以提供帮助吗?
我尝试设置一个处理每个字符打印的 for 循环。我试图制作计数器,以便在打印字符时它们似乎是偏移的,因为我知道如果它们都从第 0 行开始,那么它们将并排打印。以下是我到目前为止编写的一些代码。'O' 打印,但 'K' 打印很奇怪。
int main() {
char userInputCharacter; // User input for some character
int userInputNumber; // User input for some numerical value
cout << endl
<< "Choose from among the following options: \n"
<< " 2. Display OK as an animation \n"
<< "Your choice -> ";
cin >> userInputCharacter;
cout << endl;
// Display OK as an animation
if( userInputCharacter == '2') {
cout << "How many sets of letters do you want to display? -> ";
cin >> userInputNumber;
for( int setsOfLetters = 0; setsOfLetters < userInputNumber; setsOfLetters++) {
// Display some number of blank lines. This starts as a large number the first time, then
// gets smaller each subsequent time, moving the ENTIRE set of letters vertically.
for( int numberOfBlankLines = userInputNumber; numberOfBlankLines > setsOfLetters; numberOfBlankLines--) {
cout << endl;
}
// Display one set of letters, going through and printing one "slice" of each letter at a time.
int i = 0;
int j = 4;
for( int i=0; i<8; i++) {
if( i==0) cout << " ";
else if( i==1) cout << " ";
else if( i==2) cout << " ** ";
else if( i==3) cout << " * * ";
else if( i==4) cout << "* * ";
else if( i==5) cout << "* * ";
else if( i==6) cout << " * * ";
else if( i==7) cout << " ** ";
if( j ==0) cout << " ";
else if( j ==1) cout<< " ";
else if( j ==2) cout << "* * ";
else if( j ==3) cout << "* * ";
else if( j ==4) cout << "** ";
else if( j ==5) cout << "* * ";
else if( j ==6) cout << "* * ";
else if( j ==7) cout << " ";
cout << endl;
}//end for( int i...)
// Clear the screen after the letters are displayed.
this_thread::sleep_for(chrono::milliseconds( 185)); // Sleep for 185 milliseconds
system( "clear"); // Clear the screen. Comment out this line if you don't want them erased.
}//end for( int setsOfLetters...
}//end else if( userInputCharacter == '2' ...
return 0;
}//end main()
如果我们可以建议使用for
循环if
和else
语句来解决这个问题,那对我会很有帮助。我还没有介绍函数、字符串和数组,我不想继续前进并变得更加困惑。谢谢大家。