Untitled
unknown
c_cpp
2 years ago
875 B
8
Indexable
#include <iostream>
using namespace std ;
int main() {
cout << "計數器:" << endl ; //告訴使用者這個面板是什麼作用
int counter = 0 ; //宣告一變數儲存次數
for( int i = 0 ; i < 20 ; i++ ){ //for迴圈的指令,迴圈共會進行20次。
counter = i + 1 ; //讓計數器的數值變成熟悉的從1開始
cout << "第 " << counter << " 次" << endl ; //顯示計數的次數
}
if ( counter > 20 ){ //使用if判斷計數器是否數值大於20
cout << "總共20(不含)次以上。" << endl ; //是則執行這行cout
}
if ( counter == 20 ){ //使用if判斷計數器是否數值等於20
cout << "總共20次。" << endl ; //是則執行這行cout
}
if( counter < 20 ){ //使用if判斷計數器是否數值小於20
cout << "總共20(不含)次以下。" << endl ; //是則執行這行cout
}
}Editor is loading...