新闻看到某某某喜中xxx大奖新闻。就做个彩票系统,看看要是一天一注彩票买多少期能中个小奖……
新手一匹,代码献丑
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
| #include <stdlib.h> #include <iostream> #include <cstdlib> #include <unistd.h> using namespace std; class CL{ public: int money; CL() { for(int i = 0 ; i < 7; i++){ WINnumber[i] = 0; } winH = -1; winB = -1; money = 0; }; ~CL(){}; void setWINnumber(){ for(int i = 0 ; i < 7 ; i++) { if(i < 6) { WINnumber[i] = rand()%33 + 1; for(int j = 0 ; j < i ; j++) { if(WINnumber[i] == WINnumber[j]) { i--; break; } } }else { WINnumber[i] = rand()%16 + 1; } } }; void InfoWINnumber() { cout << "中奖号码为:\n"; for (int i = 0; i < 6 ; i++) { cout << "\033[31m" << WINnumber[i] << "\033[0m "; } cout << "\033[34m" << WINnumber[6]<< "\033[0m"; }; void KJ(int a[7]) { int winH = 0; for(int i = 0 ; i < 6; i++){ for(int j = 0 ; j < 6 ;j++){ if(a[i] == WINnumber[j]){ winH++; } } } if(a[6] == WINnumber[6]){ winB = 1; }else{ winB = 0; } cout << "\n选对红球数: " << winH << "\t" << "选对蓝球数: " << winB << "\t"; if(winB == 1){ if(winH == 0||winH == 1||winH == 2){ cout << "\033[35m运气不错,中了5块!\033[0m" << endl; money = 5; } else if(winH == 3){ cout << "\033[35m小赚一把,中了10块!\033[0m" << endl; money = 10; } else if(winH == 4){ cout << "\033[35m哈哈哈,中了200块!\033[0m" << endl; money = 200; } else if(winH == 5){ cout << "\033[35m差一点就大奖,3000块也不错啦!\033[0m" << endl; money = 3000; } else if(winH == 6){ cout << "\n\033[35m***********oh my God*************" << "\n" << "\n\n\t" << "你中头奖了" << "\t\n\n" << "\t" << "奖金1000万!!!" << "\t\n\n\n" << "*********************************\033[0m" << endl; money = 10000000; }else{ cout << "很遗憾,未中奖,下次再来吧!" << endl; } } else if(winB == 0) { if(winH == 4){ cout << "\033[35m小赚一把,中了10块!\033[0m" << endl; money = 10; } else if(winH == 5){ cout << "\033[35m哈哈哈,中了200块!\033[0m" << endl; money = 200; } else if(winH == 6){ cout << "\033[35m二等奖!!!500万!( $ _ $ )\033[0m " << endl; money = 5000000; }else{ cout << "\033[33m【很遗憾,未中奖,下次再来吧!】\033[0m" << endl; } } }; private: int WINnumber[7]; int winH; int winB; }; int main() { srand( (unsigned)time( NULL ) ); cout << "\n\033[33m************** welcome ****************" << "\n" << "*****************************************" << "\n" << "\t" << "本程序模拟彩票开奖"<< "\n" << "\t" << " 祝君早中大奖!!!" << "\t" << "\n" << "*****************************************\033[0m" << endl; Loop3: int Choicenumber[7] = {0 , 0 , 0 , 0 , 0 , 0}; int Periods = -1; for(int i = 0 ; i < 7 ; i++ ) { if(i < 6) { Loop1: cout << "请输入第 " << i + 1 << " 号\033[31m红球\033[0m(1~33) "; cin >> Choicenumber[i]; if(Choicenumber[i] > 0 && Choicenumber[i] < 33) { for(int j = 0 ; j < i ; j++) { if(Choicenumber[i] == Choicenumber[j]) { cout << "您已经选过这个号码了,请重新输入(+﹏+)" << endl; goto Loop1; } } } else{ cout << "\033[36m选择错误:红球只能选择1~33号,请重新选择(*.*)\033[0m" << endl; Choicenumber[i] = 0; goto Loop1; } }else{ Loop2: cout << "请输入\033[34m蓝球\033[0m(1~16) "; cin >> Choicenumber[6]; if((Choicenumber[6] < 1 || Choicenumber[6] > 16)){ cout << "\033[36m选择错误:蓝球只能选择1~16号,请重新选择(-.-)\033[0m" << endl; goto Loop2; } } }; int temp = 0; for (int i = 0; i < 5; i++) { for(int j = 0; j < 5-i; j++) { if(Choicenumber[j] > Choicenumber[j+1]) { temp = Choicenumber[j]; Choicenumber[j] = Choicenumber[j+1]; Choicenumber[j+1] = temp; } } } cout <<"您选择的彩票号码是" << "\n"; for(int i = 0 ; i < 6 ; i ++ ) { cout << "\033[31m"<<Choicenumber[i] << " "; } cout << "\033[34m" <<Choicenumber[6] << "\033[0m" <<endl; Loop4: int WINmoney = 0; int WIN5 =0; int WIN10 =0; int WIN200 =0; int WIN3000 = 0; int WIN500W = 0; int WIN1000W = 0; do{ cout <<"\033[33m请输入计划要买的期数(大于1)\033[0m:" << endl; cin >> Periods; if (Periods < 1) { cout << "输入不正确,\n"; } }while(Periods < 1); for(int i = 0 ; i < Periods ; i++) { cout <<"\033[33m"<< "第 " << i + 1 << " 期" << "\033[0m"; CL *P1 = new CL(); P1->setWINnumber(); P1->InfoWINnumber(); P1->KJ(Choicenumber); WINmoney = WINmoney + P1->money; if(P1->money == 5 ){ WIN5++; } else if(P1->money == 10 ){ WIN10++; } else if(P1->money == 200 ){ WIN200++; } else if(P1->money == 3000 ){ WIN3000++; } else if(P1->money == 5000000 ){ WIN500W++; } else if(P1->money ==10000000){ WIN1000W++; } delete P1; P1 = NULL; cout << "已经花费:"<< (i+1)*2 << "\t"<<"已赢得奖金:" << WINmoney << endl; cout << "获得5元 [" << WIN5 << "] 次 " << "获得10元 [" << WIN10 << "] 次 " << "获得200元 [" << WIN200 << "] 次 " << "\n" << "获得3000元 [" << WIN3000 << "] 次 " << "获得500w [" << WIN500W << "] 次 " << "获得1000w [" << WIN1000W << "] 次" << "\n" <<endl; } cout <<"\033[32m您本次选择的彩票号码是\033[0m "; for(int i = 0 ; i < 6 ; i ++ ) { cout << "\033[31m"<<Choicenumber[i] << " "; } cout << "\033[34m" <<Choicenumber[6] << "\033[0m" <<endl; int ok = 0; do{ cout << "\033[33m您可以重新选择购买期数或者重新选号" << "\n" << "1.重新选择购买期数" << "\n" << "2.重新选号" << "\n" << "3.退出系统\033[0m" << endl; cin >> ok; }while(ok != 1 && ok != 2 && ok != 3); if(ok == 1){ goto Loop4; }else if(ok == 2){ goto Loop3; } return 0; }
|
运行图




不考虑瞎猫碰死耗子中1000w,大概扔100块回来25块的样子。
好吧,彩票就是75%的赔率赌个希望。
还是不考虑系统作弊的情况~~理论上作弊轻轻松松。
不过希望还是要有的,万一中了呢?23333
再说比起某游开箱子的爆率想想还是挺(yi)良(yang)心(keng)的(die).
遇到的坑rand()生成随机数一样
#include <stdlib.h>
srand( (unsigned)time( NULL ) );//设置随机数种子