- 最後登錄
- 2024-11-19
- 在線時間
- 42 小時
- 註冊時間
- 2013-6-19
- 閱讀權限
- 20
- 精華
- 0
- UID
- 13205727
- 帖子
- 59
- 積分
- 28 點
- 潛水值
- 12630 米
| 若新密碼無法使用,可能是數據未更新。請使用舊密碼看看。 底下為簡單的代碼給您參考:- #include <iostream>
- #include <conio.h>
- #include <time.h>
- #include <Windows.h>
- using namespace std;
- void Prompt()
- {
- system("cls");
- cout<<"There are two coins. Please guess Heads or Tails:\n";
- cout<<"Press 'a' to guess head x 2.\n";
- cout<<"Press 'b' to guess head x 1, tail x 1.\n";
- cout<<"Press 'c' to guess tail x 2.\n";
- cout<<"Please input your answer: ";
- }
- int main(void)
- {
- char result, ans;
-
- while(true)
- {
- Prompt();
- ans = _getche();
- if(ans<97||ans>99)
- {
- cout<<"\nPlease pick up an answer among 'a', 'b', or 'c' !!!";
- Sleep(1000);
- }else
- break;
- }
-
- srand(time(NULL));
- result = (char)(97 + rand()%3);
-
- cout<<"\nYour answer is "<<ans<<".\n";
- cout<<"Result is "<<result<<".\n";
- (ans==result) ? cout<<"You Win !\n" : cout<<"You Lose !\n";
-
- system("pause");
- return 0;
- }
複製代碼 ... |
|