#include <cstdlib>
#include <iostream>
#include <time.h>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
cout<<"作業0604_猜這期的大家樂開獎的六個數值\n";
cout<<"請問是否要執行本程式?若'是'請輸入\"Y\"!若'否'請輸入\"N\"!你的意思是 : ";
char choice;
cin>>choice;
while (choice=='Y'||choice=='y')
{
int lotto[6]; //存放樂透號碼
int check[43]={0}; //紀錄是否已選取
int i,chk;
srand(time(NULL));
for(i=0;i<6;i++){
do{
lotto[i] = rand()%42+1; // 亂數指定號碼
chk = lotto[i]; // 把號碼存在chk 簡化下一行的長度 方便閱讀
}while(check[chk]!=0);
check[chk] = 1; // 設定為已選
cout<<"\n這期的大家樂透開獎的六個數值分別是:"<< lotto[i]<<"\n";
}
cout<<"請問是否要執行本程式?若'是'請輸入\"Y\"!若'否'請輸入\"N\"!你的意思是 : ";
cin>>choice;
}
system("PAUSE");
return EXIT_SUCCESS;
}
留言列表