標題:
052 猜數字遊戲進階版
[打印本頁]
作者:
游東祥
時間:
2014-5-10 13:42
標題:
052 猜數字遊戲進階版
遊戲啟動後讓玩家選擇難易度"簡單"、"進階"、"高階"三種。
簡單的範圍為 1~99
進階的範圍為 1~999
高階的範圍為 1~9999
每次遊戲最多可猜測10次。
作者:
林宇翔
時間:
2014-5-10 13:52
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int a = 0;
int b = 0;
int c = 0;
cout << "請選擇難度(輸入代碼)" << endl;
cout << "1.初階-1~99" << endl;
cout << "2.中階-1~999" << endl;
cout << "3.高階-1~9999" << endl;
cout << "請選擇:" << endl;
cin >> c;
if(c == 1)
{
a = (rand() % 99) + 1;
}
if(c == 2)
{
a = (rand() % 999) + 1;
}
if(c == 3)
{
a = (rand() % 9999) + 1;
}
for(int i = 1; i <= 10; i++)
{
cout << "☆請輸入第" << i << "次★:" ;
cin >> b;
if(b == a)
{
cout << "★恭喜你答對了,答案為:" << a << "☆" << endl;
break;
}
if(b < a)
{
cout << "在大點" << endl;
}
if(b > a)
{
cout << "在小點" << endl;
}
if(i == 10)
{
cout << "★恭喜你答錯了,答案為:" << a << "☆" << endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
李允軒
時間:
2014-5-17 15:43
本帖最後由 李允軒 於 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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2