实现一个投骰子游戏。你有1000金币,每次可投100个金币买大或买小。如果猜对了,可得本金及奖励共计180金币,如果猜错了每次损失100金。测试时投币10次,每次选择big或small,看看你最后剩下多少金币。
参考输入格式:b b s s b b s b b s参考输出格式剩余500金
//金币游戏(随机数)
#include <stdlib.h>#include <time.h>#include<iostream>using namespace std;int main(){ char c; int num,tot=1000; srand((unsigned) time(NULL)); //放里面调多次时间太短种子相同产生数就相同||为什么放外面就可以产生随机数了呢||难道每次调用rand会重新调一次srand? for(int i=0;i<10;i++){ cin>>c; tot-=100; num=rand()% 2; cout<<num; if(c=='s'&&num==0||c=='b'&&num==1) tot+=180; } cout<<"剩余"<<tot<<"金"; return 0;}![在这里插入图片描述](https://img-blog.csdnimg.cn/20200321222105267.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NocmlzbGVlcXVlZW4=,size_16,color_FFFFFF,t_70)