c++设计一个体育易做图的投彩和开奖过程!
要求:体彩的中奖等级分为特等奖(7位数字全部吻合),一等奖(6个连续的数字吻合),二等奖(5个连续的数字吻合)、三等奖(4个连续的数字吻合)和安慰奖(2个连续的数字吻合),设立奖励规则,各个等级的奖金金额自定。每个彩民一次可以下多注,每注2元。详细一点,谢谢
追问:
要求:体彩的中奖等级分为特等奖(7位数字全部吻合),一等奖(6个连续的数字吻合),二等奖(5个连续的数字吻合)、三等奖(4个连续的数字吻合)和安慰奖(2个连续的数字吻合),设立奖励规则,各个等级的奖金金额自定。每个彩民一次可以下多注,每注2元。详细一点,谢谢
追问:
答案:以前我回答过个一摸一样的问题。你看下能不能调试#include <iostream>
#include <iomanip>
#include <ctime>
#include <vector>
using namespace std;//奖项设置
const int _1st = 10000;
const int _2nd = 1000;
const int _3rd = 100;
const int _4th = 10;
const int _5th = 2;
//易做图的结构
typedef struct _Lottery{
int number[7];
}Lottery;
class Game{
private:
int target[7];//本期中奖号码
vector<Lottery> list;//玩家购买的易做图列表
int money; //玩家当前的金额
int _1stN; //特等奖中奖情况
int _2ndN; //一等奖中奖情况
int _3rdN; //二等奖中奖情况
int _4thN; //三等奖中奖情况
int _5thN; //安慰奖中奖情况public:
Game(int cash)
: money(cash),
_1stN(0),
_2ndN(0),
_3rdN(0),
_4thN(0),
_5thN(0)
{}~Game()
{
list.clear();
}//随机获得本期中奖号码
void setNumber(){
srand(unsigned(time(NULL)));
for (int i=0; i<7; i++){
target[i] = rand()%10;
}
}//玩家购买易做图
void buy(){
cout<<endl<<endl
<<"输入易做图号码,以空格键隔开"<<endl;
Lottery temp;
int input;
for (int i=0; i<7; i++){
cin>>input;
temp.number[i] = input%10;
}
list.push_back(temp);
}//显示所有易做图
void printAllLottery(){
cout<<endl<<"你目前所有的所有易做图为:"<<endl;
for (int i=0; i<list.size(); i++){
cout<<i+1<<". ";
for (int j=0; j<7; j++){
cout<<list[i].number[j]<<" ";
}
cout<<endl;
}
}//比对获奖号码,统计所有获奖情况
void compare(){
int count,max;
for (int i=0; i<list.size(); i++){
count = 0;
max = 0;
for (int j=0; j<7; j++){
if (list[i].number[j]!=target[j])
count=0;
else{
count++;
if (max<count)
max = count;
}
}
switch(max){
case 2:
_5thN++;
break;
case 4:
_4thN++;
break;
case 5:
_3rdN++;
break;
case 6:
_2ndN++;
break;
case 7:
_1stN++;
break;
}
}
}//重置
void reset(){
_1stN = 0;
_2ndN = 0;
_3rdN = 0;
_4thN = 0;
_5thN = 0;
}//统计奖金
void result(){
int get = _5thN*_5th+_4thN*_4th+_3rdN*_3rd+_2ndN*_2nd+_1stN*_1st;
cout<<"\n你在这一期中获得: "<<get<<"元"<<endl<<endl;
money+=get;
}//游戏主界面
void mainScreen(){
int choose;
int i=10020;
char c = 'y';
while(1){
this->setNumber();
cout<<endl<<endl
<<"第 "<<i<<" 期体育易做图"<<endl<<endl
<<"特等奖: "<<setw(10)<<_1st<<"元"<<endl
<<"一等奖: "<<setw(10)<<_2nd<<"元"<<endl
<<"二等奖: "<<setw(10)<<_3rd<<"元"<<endl
<<"三等奖: "<<setw(10)<<_4th<<"元"<<endl
<<"安慰奖: "<<setw(10)<<_5th<<"元"<<endl<<endl
<<"当前你共有现金: "<<money<<"元"<<endl
<<"1. 购买易做图"<<endl
<<"2. 退出"<<endl<<endl
<<"输入你的选择: ";
cin>>choose;
switch(choose){
case 1:
if (money<2){
cout<<"\n你没有足够的金钱购买易做图,退出"<<endl;
return;
}
while (money>=2&&(c=='y'||c=='Y')){
this->buy();
money-=2;
cout<<"\n是否继续购入(Y/N): ";
cin>>c;
}
cout<<"\n\n本期中奖号码: ";
for (int i=0; i<7; i++){
cout<<target[i]<<" ";
}
cout<<endl;
this->compare();
this->result();
this->reset();
list.clear();
break;
case 2:
return;
default:
cout<<"\n无法识别选项,自动跳入下一期"<<endl;
break;
}
i++;
}
}};
int main(){
Game test(20);
test.mainScreen();
return 0;
}