Skip to content

Instantly share code, notes, and snippets.

@uhfx
Created June 8, 2014 14:58
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 uhfx/433cc0f4d1d1848f4170 to your computer and use it in GitHub Desktop.
Save uhfx/433cc0f4d1d1848f4170 to your computer and use it in GitHub Desktop.
#include <iostrea>
#include <cstdlib>
#include <ctime>
using namespace std;
int funcfor();
int main()
{
double answer;
int num;
int count=0;
funcfor();
cout << "計算ゲーム";
funcfor();
cout << "\n" << endl;
cout << "計算したい問題数を入力してください" << endl;
cout << ">>";
cin >> num;
if (num==0) {
cout << "終了します" << endl;
}
cout << num << "問出題します" << endl;
cout << "割り算は整数値だけ入れてください" << endl;
//数当てここから
cout << "出題を開始します" << endl;
system("sh time.sh");
for (int i=0; i<num; i++) {
srand((unsigned)time(NULL));
int n=rand()%100+1;
int m=rand()%100+1;
int mondai=rand()%4+1;
switch(mondai) {
case 1: {
cout << n << "+" << m << "=";
cin >> answer;
if (answer==n+m) {
cout << "正解です" << endl;
count++;
}
else 
cout << "不正解です" << endl;
break;
}
case 2: {
int mon=rand()%2+1;
if(mon==2) {
cout << n << "-" << m << "=";
cin >> answer;
if(answer==n-m) {
cout << "正解です" << endl;
count++;
}
else 
cout << "不正解です" << endl;
}
if(mon==1) {
cout << m << "-" << n << "=";
cin >> answer;
if (answer==m-n) {
cout << "正解です" << endl;
count++;
}
else 
cout << "不正解です" << endl;
}
break; 
}
case 3: {
cout << n << "X" << m << "=";
cin >> answer;
if (answer==n*m) {
cout << "正解です" << endl;
count++;
}
else 
cout << "不正解です" << endl;
break;
}
case 4: {
int monwari=rand()%100+1;
int monwari2=rand()%100+1;
if (monwari > monwari2) {
cout << monwari << "÷" << monwari2 << "=";
cin >> answer;
if(answer==(int)monwari/monwari2) {
cout << "正解です" << endl; 
count++;
}
else 
cout << "不正解です" << endl;
}
if (monwari < monwari2) {
cout << monwari2 << "÷" << monwari << "=";
cin >> answer;
if(answer==(int)monwari2/monwari) {
cout << "正解です" << endl;
count++;
}
else 
cout << "不正解です" << endl;
}
}
}
cout << endl;
funcfor();
cout << "成績";
funcfor();
cout << endl;
cout << count << "/" << num << "回正解しました" << endl;
return 0;
}
int funcfor()
{
for(int i=0; i<10; i++)
cout << "=";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment