返回顶部

收藏

21点游戏的c++实现

更多
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
 int loopx;
 loopx = 1;
 while(loopx == 1){
  int computer;
  int player;
  int addon;
  srand ( time(NULL) );
  computer = rand() % 23 + 4;
   player = rand() % 21 + 4;
    addon = rand() % 11 + 1;
     int loop = 1;
  while (loop == 1){
     cout << "New round... your cards: " << player;
  string response;
   cin >> response;
   if(response == "done"){
               cout << "ok then...";
               loop = 0;
               }
   if(response == "hitme"){
              cout << "ok then...";
           player = player + addon;
           cout << "your new cards are equal to " << player;
               }
               if(player>computer){
                    if(player<22){
                                  cout << "you won! Computer's cards:" << computer;
                                  loop = 0;
                                  }
                    if (player>21){
                                   cout << "you lose! Computer's cards:" << computer;
                                   loop = 0;
                                   }
                    }
                if(computer>player){
                                    if(computer<22){
                                                  cout << "You lose! Computer's cards:" << computer;  
                                                    }
                                    if(computer>21){
                                         cout << "You won! Computer's cards:" << computer;
                                         }
                                    }  
               }
               }
system ("pause>nul");
return 0;
}

标签:c++,blackjack

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. 绚丽也尘埃 发表 2013-01-05 06:22:35 JsonCpp使用优化(三)
  2. mortoray 发表 2013-02-21 17:54:48 Leaf: Preserving “lvalue” status
  3. Herb Sutter 发表 2012-06-01 23:04:27 We’re hiring (again & more)
  4. Herb Sutter 发表 2012-10-29 16:35:29 The Future of C++: Live broadcast this Friday
  5. Boris Kolpackov 发表 2012-09-18 09:14:47 ODB 2.1.0 released
  6. CppLive 发表 2012-04-15 02:46:53 Linux下的Make与Makefile
  7. 陈皓 发表 2013-04-29 08:17:40 “C++的数组不支持多态”?
  8. Qiang 发表 2011-01-04 16:25:00 C++ 不给力之不可继承
  9. CppLive 发表 2013-06-24 14:52:04 MAC跟Linux下Android交叉编译环境搭建
  10. mortoray 发表 2013-07-14 12:20:28 Rejuvenating the ternary conditional with optional
  11. 刘 凡超 发表 2013-01-02 13:29:29 WebKit/WTF中的智能指针之OwnPtr
  12. Solstice 发表 2013-10-09 07:40:38 C++面试中string类的一种正确写法

发表评论