看了chenguo的文章
于是也写点东西#include<iostream>
#include<cstdlib>
#include "windows.h"
using namespace std;
int main()
{
double MagNum;
int Max = 2;
int money = 100;
int iinput;
int inputmoney;
while(1)
{
if (money == 0)
{
cout << "game over!";
Sleep(2000);
return 0;
}
cout << "now,you have $" << money << "\nbig or small?\nplease input 2 or 1\ninput 0 to exit\n";
cin >> iinput;
cout << "how much\n";
cin >> inputmoney;
MagNum = rand() % Max + 1;
if ((iinput == 1) || (iinput == 0) || (iinput == 2))
{
if (inputmoney > money)
{
cout << "you don not have so much money\n";
}
else
{
switch(iinput)
{
case 0:
return 0;
case 1:
case 2:
if (iinput == MagNum)
{
money += inputmoney;
cout << "win\n";
}
else
{
money -= inputmoney;
cout << "lost\n";
}
break;
}
}
}
else
{
cout << "wrong!\n";
}
}
return 0;
}
[ 本帖最后由 zapline 于 2009-2-7 18:50 编辑 ] |