我尝试将随机函数用于不同的事情。 现在它的工作原理,但我得到一个问题是我想在我的代码中随机生成F,但他们需要成为后面的数组。此外,我需要使用它,如果我需要做1 1我认为我的代码将太长,混乱。 你知道我该怎么做?C++ Random&Array
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
srand(time(0));
//random numbers 1 to 10 for Time:
int t = rand() % 10 + 1 ;
cout << "There is "<< t << " Time;
int* F1 = new int [t];
int* F2 = new int [t];
int* F3 = new int [t];
int* F4 = new int [t];
int* F5 = new int [t];
cout << "Time per F: 0 Not available, 1 available;
//For F1
for(int i = 0; i < t; i++){
//random numbers 0 or 1:
F1[i] = rand() % 2 ;
}
cout << "The Time for F1 is ";
for(int a = 0; a < t; a++){
cout << " "<< F1[a] <<" ";
}
//For F2
for(int j = 0; j < t; j++){
//random numbers 0 or 1:
F2[j] = rand() % 2 ;
}
cout << "The Time slot for F2 is ";
for(int b = 0; b < t; b++){
cout << " "<< F2[b] << " ";
}
return 0;
}
谢谢
编辑:通过该解决方案,你给我的帮助,以找到解决方案 我做诠释F [EM] [T]
'cout <<“Time per F:0不可用,1可用;'此行语法错误编辑:此代码中有超过1个语法错误。 – mostruash 2013-03-12 04:18:20
WTB接近报价。 – WhozCraig 2013-03-12 04:27:45
欢迎来到StackOverflow。请不要提出新的问题作为编辑。如果答案帮助你解决了所述的问题,[请将其标记为已接受](http://stackoverflow.com/faq/#howtoask)并提出一个新的(特定的)问题。如果没有答案有帮助,那么你需要改变你的问题(参见[编写完美问题](http://tinyurl.com/so-hints)以获得提示)。 – Johnsyweb 2013-03-12 04:57:17