c语言if无法激活
我用VS做的,代码如下:
(这里把所有的空格都删了,实际语法是正确的,某些操作部分没有写)
#include<stdio.h> //标准输入、输出函数库
#include<stdlib.h> //标准函数库
#include<string.h> //字符串函数库
#include<time.h> //时间处理函数库
#include<windows.h> //系统操作函数库
#include<dos.h>
#include<conio.h> //屏幕操作函数库
#define HELP1 "+---------------=========================Help=========================-----------------+ "
#define HELP2 "| This is a turn-based game. | "
#define HELP3 "| You will play with computer. | "
#define HELP4 "| You just have to kill him. | "
#define HELP5 "| In the process, you can cause harm to the other person, or return blood to yourself. | "
#define HELP6 "| Maximum 3 health per person. | "
#define HELP7 "+---------------=======================Start Game!====================-----------------+ a" //设置宏函数——帮助内容
#define UD "****************************************************************************************"
#define GAMEOVER "*-------------=========================GAME OVER========================---------------* "
#define YOUWIN "*--------------========================YOU WIN!========================----------------* "
int bloodp = 3; //设置玩家血量
int usep; //设置玩家选择项
int p; //设置玩家使用选项
int bloodc = 3; //设置电脑血量
int usec; //设置电脑选择项
int c; //设置玩家使用选项
void main()
{
system("color F9");
while(1) //循环,避免触发帮助后退出程序
{
printf("Welcome to“Triple kill” ");
printf("Enter “1”to get help Enter “2” to start game. "); //欢迎语
int a; //设置选项输入变量
a = getch(); //录入选项
if( a == 1 ) //触发帮助内容机制
{
printf(HELP1);
printf(HELP2);
printf(HELP3);
printf(HELP4);
printf(HELP5);
printf(HELP6);
printf(HELP7); //调用宏函数
}
if( a == 2 ) //触发游戏开始
{
system("clear"); //清屏
printf("Hello! I'm a computer.I'll kill you! a");
while(1 == 1) //反复循环直至结束
{
if(bloodp == 0 || bloodc == 0) //判定结束机制
break;
printf("Tips:“1” to use rock,“2” to use paper,“3” to use scissors. "); //提示
usep = getch(); //等待玩家选择
switch(usep) //触发玩家语句
{
case 1 :
printf("Player use rock! a");
break;
case 2 :
printf("Player use paper! a");
break;
default:
printf("Player use scissors! a");
}
srand( (unsigned) time (NULL) ); //调取时间值,决定电脑回合
usec = rand() % 2;
switch(usec) //触发电脑语句
{
case 1 :
printf("Computer use rock! a");
break;
case 2 :
printf("Computer use paper! a");
break;
default:
printf("Computer use scissors! a");
}
}
if(bloodp == 0)
{
printf(UD);
printf(GAMEOVER);
printf(UD);
}
if(bloodc == 0)
{
printf(UD);
printf(YOUWIN);
printf(UD);
}
Sleep(10000);
break;
}
}
}
可是输出是这样的:(输入1或2都是这样的,if无法激活)