发现抽取的数值会有重复情况出现,如何避免啊,求问,总是改出乱码555555
源程序如下:
//抽奖程序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
#define MAX_NUM 10
#define One 1
#define Two 2
#define Three 5
void suijishu(char phone[]);
int main(int argc, char * argv[])
{
char phone[MAX_NUM][12];
int count;
int M;
int flag;
cout << "输入需要几组号码:" << endl;
cin >> M;
srand(time(0));
for (count = 0; count<M; count++)
{
memset(phone[count], 0, sizeof(phone[count]));
suijishu(phone[count]);
}
ofstream outfile("data.txt");
for (count = 0; count<M; count++)
{
cout << phone[count] << endl;
outfile << phone[count] << endl;
}
outfile.close(); //关闭文件
//抽奖
count = rand()%10;
cout << "一等奖:" << phone[count] << endl;
cout<<endl;
for (count = 0; count < 2; count ++)
{
cout << "二等奖:" << phone[count] << endl;
}
cout<<endl;
for (count = 0; count < 5; count ++)
{
cout << "三等奖:" << phone[count] << endl;
}
return 0;
}
//随机数
void suijishu(char phone[])
{
char p1[5] = {"1781"};
strcpy(phone, "1781");
int i;
for (i = 4; i<11; i++)
phone[i] = rand() % 10 + '0';
}