您的位置:首页 > 编程语言 > C语言/C++

C语言小游戏

2018-02-03 18:32 45 查看
1.与电脑进行石头剪刀布
#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main()

{

 char game;

 int computer;

 int result;

 while (1)

 {

  printf("this is a caiquan game,please enter your result:\n");

  printf("剪刀:A\n石头:B\n布:C\n不玩:D\n");

  game = getchar();

  switch (game)

  {

  case 65:

  case 97:

   game = 4; break;

  case 66:

  case 98:

   game = 7; break;

  case 67:

  case 99:

   game = 10; break;

  case 68:

  case 100:

   return 0;

  default:

   printf("error!");

   getchar();

   getchar();

   system("cls");

   return 0;

   break;

  }
  computer = rand() % 3;

  result = computer + (int)game;

  printf("the result that computer:\n");

  switch (computer)

  {

  case 0:printf("剪刀:\n"); break;

  case 1:printf("石头:\n"); break;

  case 2:printf("布:\n"); break;

  }

  printf("the result of you :\n");

  switch (game)

  {

  case 4:printf("剪刀:\n"); break;

  case 7:printf("石头:\n"); break;

  case 10:printf("布:\n"); break;

  }

  if (result == 6 || result == 7 || result == 11)

   printf("you are winner!");

  else if (result == 5 || result == 9 || result == 10)

   printf("the computer win");

  else printf("平手");

  system("pause>nul&&cls");

 }

 return 0;

}
2.对字符串中元音字母进行统计

#include<stdio.h>

#include<string.h>

int main()

{

 int tong(char string[]);

 int c;

 char str[80];

 printf("the string:\n");

 gets_s(str);

 c=tong(str);

 printf("the yuanyin zi mu:%d", c);

 getchar();

 getchar();

 return 0;

}

int tong(char string[])

{

 int i,c=0;

 for (i = 0; string[i] != '\0'; i++)

 {

  if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || string[i] == 'o' || string[i] == 'u')

   c++;

  else ;

 }

 return(c);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: