写了一个关于抽取学号的程序,如下:
#include<iostream>
#include<fstream>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<ctime>
#include<cstdlib>
using namespace std;
const string PASSWORD = "070714";
int a, j, k, i, co = 0;
int arr[55] = {};
char m[200] = {};
string in = "", n = "";
void instructions() {
cout << setw(60) << "使用说明";
cout << "重启程序请输入“重启”,关闭程序请输入“退出”。" << endl;
cout << "输入一个小于班级人数的数字,将输出一些随机数。" << endl;
cout << "输入记事本模式以进入记事本模式,此时你可以输入文本,按Enter键确定。" << endl;
cout << "输入打开记事本以查看记事本的内容。" << endl;
cout << "\n\n\n还有彩蛋等你来试!\n\n\n";
system("pause");
}
void show() {
system("cls");
system("color F1");
cout << setw(50) << "抽奖程序" << setw(55) << "[Version 1.6]" << endl;
cout << setw(60) << "重启程序请输入“重启”,关闭程序请输入“退 出”。" << endl;
cout << "请输入人数:";
}
int getrand() {
srand(time(0)); //随机种子
int a;
a = rand() % 1000 + 1;
while (a >= 1000)a -= 55;
return a;
}
int main()
{
show();
arr[55] = {};
m[200] = {};
a = i = j = k = co = 0;
system("start osk");
cin >> in;
cout << endl;
if (in == "退出") {
exit(0);
}
else if (in == "重启") {
system("start choujiang.exe");
exit(1);
}
else if (in == "打开记事本") {
ifstream in;
in.open("NotePad.lpr");
while (in >> m)in >> m;
cout << m << endl;
in.close();
main();
}
else if (in == "记事本模式") {
system("cls");
ofstream out;
system("color F4");
cout << setw(70) << "记事本模式" << endl;
out.open("记事本.lpr");
cin >> n;
out << n;
out.close();
cout << "成功!" << endl;
system("pause");
system("cls");
main();
}
else if (in == PASSWORD) {
cout << "管理员模式" << endl;
system("pause");
system("cls");
show();
cin >> in;
system("cls");
show();
cout << endl << "中奖号码是" << in << "号" << endl;
system("pause");
main();
}
else {
stringstream ss;
ss << in;
ss >> i;
}
if (i > 55) {
cout << "人数超过55!!!" << endl;
system("pause");
system("cls");
main();
}
while (j <= i - 1) {
a = getrand();
while (co <= j) {
if (a == arr[j])
continue;
else
arr[j + 1] = a;
j++;
}
}
sort(arr, arr + i - 1);
for (int z = 0; z < i; z++)cout << "中奖号码是" << arr[z] << "号" << endl;
system("pause");
main();
}
报错图片:![图片说明](https://img-ask.csdn.net/upload/202001/25/1579938675_183844.png)