我正在制作一个程序,为某人输入的一定数量的数字生成一个随机的 x 和 y 点。由于某种原因,我的随机数没有正确存储在数组中。我在生成点的循环中输出数组,最后在 for 循环中输出数组,y 坐标不相同:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand((unsigned)time(0));
int mounds =0;
//prompt for number of mounds, uncertainty, and number of sites
cout <<"Please enter the number of mounds at the site: ";
cin >> mounds;
//declaration of an array that will hold the x and y for each mound
int moundArray [mounds][1];
for(int i =0; i < mounds; i++)
{
//generate a random x
moundArray [i][0] = rand()%1331;
cout <<"You just generated an x of: " << moundArray [i][0] << endl;
//sleep(1);
//generate a random y
moundArray [i][1] = rand()%1743;
cout <<"You just generated a y of: " << moundArray [i][1] << endl;
//sleep(1);
}
//for loop to display my results
for(int j =0; j < mounds; j++)
{
cout <<"random x: " << moundArray [j][0] << endl;
cout <<"random y: " << moundArray [j][1] << endl;
}
return 0;
}