Skip to content

Instantly share code, notes, and snippets.

@hckim16
Created February 13, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hckim16/269461d1e621e7131f839dfccd0c91d0 to your computer and use it in GitHub Desktop.
Save hckim16/269461d1e621e7131f839dfccd0c91d0 to your computer and use it in GitHub Desktop.
Coding loop, modulo and following directions
//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