Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
数当てさせゲーム
#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
You can’t perform that action at this time.