switch statement - Program that displays all multiples of 7 between 1 and 100 C++ -


how write program switch condition statement instead of if?

#include <iostream> using namespace std; int main() {     int i;     (i = 1; <= 100; i++) {         if ((i % 7 == 0) && (i > 0)) {             cout << << endl;         }     }      return 0; } 

it sounds little unfamiliar switch statement. switch statement if-else statement, except isn't boolean argument. asks: tell me value of . , each case (possible outcome), has follow action.

so want ask: tell me value of number, modulus 7. if zero, add 1 counter. if 1, .

so code should have general structure of:

switch(i%7):    case 0{increment counter or display std. out or store in array}    case 1{other action} 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -