- ロト6シミュレーションプログラムNo.1
一回のみロト6の抽選をします。アプリケーションはこちらからダウンロードしてください
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define N 6
int numcmp(const void *a, const void *b); //関数プロトタイプの宣言
bool match01(int a[]);
bool match02(int b[],int i);
bool match03(int c[],int j);
int main(){
int roto6[N],mark[N],bonus; //roto6 :当選番号
//mark :自分が選んだ番
//bonus :ボーナス番号
int i=0,j=0,k=0,count,error=0;
srand((unsigned int) time(0)); //time関数により毎回初期値を変えている
cout <<"---------------ロト6シミュレーションプログラム1------------------"<<endl<<endl;
cout <<"1〜43の6つの数値を入力してください"<< endl;
do{
cout <<"-----------------数値入力-----------------"<<endl;
if(error) cout <<"同じ番号が入力されています"<<endl<<"もう一度入力し直してください"<<endl;
do{
cout << i+1<< "つめの番号を入力してください::";
cin>> mark[i];
if(mark[i]>=1&&mark[i]<=43) i++;
else cout<<"1〜43までの数値を入力してください"<<endl<<endl;
}while(i<N);
/*------------データのソート---------------*/
qsort(mark,N,sizeof(int),numcmp);
i=0; error++;
}while(match01(mark));
count=0;
cout<<endl<<"-----------------☆当選番号☆-----------------"<<endl;
do{
/*-------------当選番号の割り当て--------------*/
for(i=0; i<N;i++){
roto6[i] = rand()%43+1;
}
/*------------データのソート---------------*/
qsort(roto6,N,sizeof(int),numcmp);
}while(match01(roto6)); //すべて違う数値であればループから抜ける
/*-------------ボーナス数字の割り当て----------------*/
do{
bonus = rand()%43+1;
}while(match02(roto6,bonus));
for(i=0; i<N;i++){
if(i!=N-1) cout <<roto6[i]<<",";
else cout <<roto6[i]<<endl;
}
cout <<"ボーナス数字::"<<bonus<<endl<<endl;
/*------------数字が当たっている数の個数のカウント------------*/
i=0;
do{
for(j=0;j<N;j++){
if(roto6[i]==mark[j]) count++;
}
i++;
}while(i<N);
cout <<count<< "個当たりました"<<endl;
/*--------------当選結果の表示------------------*/
switch(count){
case 0:
case 1:
case 2: cout<<"賞金はでず残念!またチャレンジしてね♪"<<endl;
break;
case 3: cout<<"おめでとうございます"<<endl<<"1,000円当たりました"<<endl;
break;
case 4: cout<<"おめでとうございます"<<endl<<"9,500円当たりました"<<endl;
break;
case 5:
if(match03(mark,bonus)) cout<<"おめでとうございます"<<endl<<"1500万円当たりました"<<endl;
else cout<<"おめでとうございます"<<endl<<"50万円当たりました"<<endl;
break;
case 6: cout<<"おめでとうございます"<<endl<<"1億万円当たりました"<<endl;
break;
default:cout <<"Programing error"<<endl;
}
cout <<"Press any key to continue";
cin>>count;
}
int numcmp(const void *a, const void *b)
{
return *((int *)a) - *((int *)b);
}
bool match01(int a[]){
if(a[0]<a[1]&&a[1]<a[2]&&a[2]<a[3]&&a[3]<a[4]&&a[4]<a[5]) return false;
else return true;
}
bool match02(int b[],int i){
if(b[0]==i||b[1]==i||b[2]==i||b[3]==i||b[4]==i||b[5]==i) return true;
else return false;
}
bool match03(int c[],int j){
if(c[0]==j||c[1]==j||c[2]==j||c[3]==j||c[4]==j||c[5]==j) return true;
else return false;
}
- ロト6シミュレーションプログラムNo.2
自分の目標とする賞金額が出てくるまで抽選をし続けます
アプリケーションはこちらからダウンロードしてください
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define N 6
int numcmp(const void *a, const void *b); //関数プロトタイプの宣言
bool match01(int a[]);
bool match02(int b[],int i);
bool match03(int c[],int j);
int main(){
int roto6[N],mark[N],bonus,aim; //roto6 :当選番号
//mark :自分が選んだ番
//bonus :ボーナス番号
//aim :目標とする一致する番号個数
int i=0,j=0,k=0,count,error=0;
srand((unsigned int) time(0)); //time関数により毎回初期値を変えている
cout <<"---------------ロト6シミュレーションプログラム2------------------"<<endl<<endl;
cout <<"1〜43の6つの数値を入力してください"<< endl;
do{
cout <<"-----------------数値入力-------------------"<<endl;
if(error) cout <<"同じ番号が入力されています"<<endl<<"もう一度入力し直してください"<<endl;
do{
cout << i+1<< "つめの番号を入力してください::";
cin>> mark[i];
if(mark[i]>=1&&mark[i]<=43) i++;
else cout<<"1〜43までの数値を入力してください"<<endl<<endl;
}while(i<N);
/*------------データのソート---------------*/
qsort(mark,N,sizeof(int),numcmp);
i=0; error++;
}while(match01(mark));
do{
cout<<"何個番号が一致するまでチャレンジし続けますか?::";
cin >>aim;
}while(aim<1||aim>6);
int jk=0;
do{ //当たるまでループし続ける
jk++;
count=0;
cout<<endl<<"-------☆当選番号☆--------"<<endl;
do{
/*-------------当選番号の割り当て--------------*/
for(i=0; i<N;i++){
roto6[i] = rand()%43+1;
}
/*------------データのソート---------------*/
qsort(roto6,N,sizeof(int),numcmp);
}while(match01(roto6)); //すべて違う数値であればループから抜ける
/*-------------ボーナス数字の割り当て----------------*/
do{
bonus = rand()%43+1;
}while(match02(roto6,bonus));
for(i=0; i<N;i++){
if(i!=N-1) cout <<roto6[i]<<",";
else cout <<roto6[i]<<endl;
}
cout <<"ボーナス数字::"<<bonus<<endl<<endl;
/*------------数字が当たっている数の個数のカウント------------*/
i=0;
do{
for(j=0;j<N;j++){
if(roto6[i]==mark[j]) count++;
}
i++;
}while(i<N);
cout <<count<< "個当たりました"<<endl;
/*--------------当選結果の表示------------------*/
cout<<"チャレンジ回数::"<<jk<<"回目"<<endl;
switch(count){
case 0:
case 1:
case 2: cout<<"賞金はでず残念!またチャレンジしてね♪"<<endl;
break;
case 3: cout<<"おめでとうございます"<<endl<<"1,000円当たりました"<<endl;
break;
case 4: cout<<"おめでとうございます"<<endl<<"9,500円当たりました"<<endl;
break;
case 5:
if(match03(mark,bonus)) cout<<"おめでとうございます"<<endl<<"1500万円当たりました"<<endl;
else cout<<"おめでとうございます"<<endl<<"50万円当たりました"<<endl;
break;
case 6: cout<<"おめでとうございます"<<endl<<"1億万円当たりました"<<endl;
break;
default:cout <<"Programing error"<<endl;
}
}while(count<aim);
cout <<"Press any key to continue";
cin>>count;
}
int numcmp(const void *a, const void *b)
{
return *((int *)a) - *((int *)b);
}
bool match01(int a[]){ //同じ数字がないか確認する関数
if(a[0]<a[1]&&a[1]<a[2]&&a[2]<a[3]&&a[3]<a[4]&&a[4]<a[5]) return false;
else return true;
}
bool match02(int b[],int i){
if(b[0]==i||b[1]==i||b[2]==i||b[3]==i||b[4]==i||b[5]==i) return true;
else return false;
}
bool match03(int c[],int j){
if(c[0]==j||c[1]==j||c[2]==j||c[3]==j||c[4]==j||c[5]==j) return true;
else return false;
}