本帖最後由 李允軒 於 2014-5-17 16:02 編輯
- #include<iostream>
- #include<ctime>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int e;
- cout << "請選擇難度(輸入代碼)" << endl;
- cout << "1.初階-1~99" << endl;
- cout << "2.中階-1~999" << endl;
- cout << "3.高階-1~9999" << endl;
- cout << "請選擇:" << endl;
- cin >> e;
-
- srand(time(NULL));
- int a,b;
- if (e == 1)
- cout << "您選擇的難度是簡單" << endl;
- {
- a = (rand() % 99) + 1;
- }
- if (e == 2)
- {
- cout << "您選擇的難度是進階" << endl;
- a = (rand() % 999) + 1;
- }
- if (e == 3)
- {
- cout << "您選擇的難度是高階" << endl;
- a = (rand() % 9999) + 1;
- }
- for (int i = 1; i <= 10; i++)
- {
- cout << "請輸入第" << i << "個數:";
- cin >> b;
- if (b == a)
- {
- cout << "恭喜你答對了! 答案是:" << a << endl;
- cout << "你總共猜了" << i << "次" << endl;
- break;
- }
- if (b < a)
- {
- cout << "再大一點"<< endl;
- }
- if (b > a)
- {
- cout << "再小一點"<< endl;
- }
- if (i == 10)
- {
- cout << "恭喜你答錯了! 答案是:" << a << endl;
- }
- }
- system("pause");
- return 0;
- }
複製代碼 |