怎样把指定的五个名字输入并且进行随机抽取呢,我每次写的程序都必须在运行后的结果中才能自己输入名字并随机抽取,可是我想要直接在程序中就把五个指定的名字输入进去,这样就避免了在输出结果后才自己输入名字
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
int main()
{
string name[5]={"aaa","bbbb","c","dd","eeeee"};
srand(time(NULL));
int i=rand()%5;
cout << name[i];
system("pause");
return 0;
}
供参考:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
int main()
{
char* name[5] = { "red","abcde","green","244dfedx","yellow" };
srand((unsigned int)time(NULL));
while (!_kbhit()) { //当没有键按下
puts(name[rand() % 5]);
_sleep(400);
}
return 0;
}