Created
February 13, 2018 05:39
-
-
Save hckim16/269461d1e621e7131f839dfccd0c91d0 to your computer and use it in GitHub Desktop.
Coding loop, modulo and following directions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This simple code assumes numbers manually inputted via cout/cin | |
//input can be entered number of ways to include std stream of string data | |
//input may change but general coding logic straightforward and will not change | |
//for loop can apply to any "FizzBuzz" problem | |
#include <iostream> | |
//add appropriate libraries | |
using namespace std; | |
int main(){ | |
int m, n, o; | |
ccout << "enter nunmber: "; | |
cin >> n; | |
cout << "enter nunmber: "; | |
cin >> m; | |
cout << "enter nunmber: "; | |
cin >> o; | |
for(int i = n; i >= 1; i--){ | |
if(i % m == 0 && i % o == 0){ | |
cout << "OUTTHINK,"; | |
} | |
else if(i % m == 0 || i % o == 0){ | |
cout << "THINK,"; | |
} | |
else if(i != 1){ | |
cout << i << ","; // for if instructions state no comma after last digit | |
} | |
else{ | |
cout << i; | |
} | |
} | |
cout << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment