急求一个猜拳小游戏的C++程序
#include<iostream.h> #include <stdlib.h> #include <time.h> void show(int input) { switch(input) { case 0:cout<<("出的是石头!"); break; case 1:cout<<("出的是剪子!"); break; case 2:cout<<("出的是布!"); break; default:; } } void compare(int inputPlay,int inputComputer) { if(inputPlay==0&&inputComputer==1||inputPlay==1&&inputComputer==2||inputPlay==2&&inputComputer==1) { cout<<("\n玩家胜!\n"); } else if(inputPlay==inputComputer) { cout<<("\n平局!\n"); } else { cout<<("\n电脑胜!\n"); } } void main() { char isGoOn; int inputPlay; int inputComputer; cout<<("猜拳游戏\n"); cout<<("游戏说明:\n\n"); cout<<("石头--0 剪子--1 布--2\n"); srand(time(NULL)); do { cout<<("\n请输入您要猜的拳:\n"); cin>>inputPlay; if(inputPlay>=0&&inputPlay<=2) { cout<<("您"); show(inputPlay); inputComputer=rand()%3; cout<<("电脑"); show(inputComputer); compare(inputPlay,inputComputer); } else { cout<<("您输入有错误!\n"); cout<<("\n说明:石头--0 剪子--1 布--2\n"); } cout<<"\n您需要继续么? (Y/N)"; cin>>isGoOn; }while(isGoOn!='N'||isGoOn!='n'); } 这段代码应该对你的思路会有用,自己再添加一下功能就好了。...
19282