Skip to content

Instantly share code, notes, and snippets.

@takoeight0821
Created May 17, 2015 09:07
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 takoeight0821/72817beb9d391b66e795 to your computer and use it in GitHub Desktop.
Save takoeight0821/72817beb9d391b66e795 to your computer and use it in GitHub Desktop.
数当てさせゲーム
#include <iostream>
int small = 1;
int big = 100;
int guessMyNumber()
{
return (small + big) / 2;
}
void smaller()
{
big = (guessMyNumber() - 1);
}
void bigger()
{
small = (guessMyNumber() + 1);
}
int main(int argc, char const* argv[])
{
int result = 0;
while (true) {
std::cout << guessMyNumber() << std::endl;
std::cout << "smaller:0, just:1, bigger: 2 > ";
std::cin >> result;
switch (result) {
case 0:
smaller();
break;
case 1:
return 0;
break;
case 2:
bigger();
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment