Skip to content

Instantly share code, notes, and snippets.

@chomado
Created August 4, 2014 01:49
Show Gist options
  • Save chomado/2a31486256e53ea288d7 to your computer and use it in GitHub Desktop.
Save chomado/2a31486256e53ea288d7 to your computer and use it in GitHub Desktop.
P312数当てゲーム。ファイル分割の練習。途中で写経飽きたので途中
#include <ctime>
#include <cstdlib>
#include "util.h"
using namespace std;
static int answer = 0;
void initialize() {
srand(time(NULL));
}
void gen_no() {
answer = rand() % (max_no + 1);
}
int judge(int cand) {
if (cand == answer)
return 0;
else if (cand > answer)
return 1;
else
return 2;
}
#include <iostream>
#include "util.h"
using namespace std;
static void prompt() {
cout << "0 ~ " << max_no << "の数:"
}
int input(int left) {
int val;
cout << "のこり" << left << "かい" << endl;
do {
prompt();
cin >> val;
} while(val < 0 || val > max_no);
return val;
}
bool confirm_retry() {
int cont;
cout << "Continue?\n <Yes..1 / No..0> : " << endl;
cin >> cout;
return static_cast<bool>(cout);
}
}
#include <iostream>
#include "util.h"
using namespace std;
int max_no = 999;
/* 以下main()関数。あきた */
// util.h
void initialize(); // 乱数の種を現在の時刻に基づいて設定
void gen_no(); // 問題の作成
int judge(int cand); // 正解の判定。candが正解かどうかを判定
int input(int left); // 回答の入力
bool confirm_retry(); // 再ゲームを行うかを確認
extern int max_no; // 当てるべき数の最大値(定義ではなく宣言)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment