I'm writing a code which will get random numbers and apply them to 15 different variables within a struct array. However, the output looks like this
"Trash pile 0 is in section1
Trash pile 0 weighs 103 LB
Trash pile 1 is in section1
Trash pile 1 weighs 103 LB
Trash pile 2 is in section1
Trash pile 2 weighs 103 LB
Trash pile 3 is in section1
Trash pile 3 weighs 103 LB
Trash pile 4 is in section1
Trash pile 4 weighs 103 LB
Trash pile 5 is in section1
Trash pile 5 weighs 103 LB
Trash pile 6 is in section1
Trash pile 6 weighs 103 LB
Trash pile 7 is in section1
Trash pile 7 weighs 103 LB
Trash pile 8 is in section1
Trash pile 8 weighs 103 LB
Trash pile 9 is in section1
Trash pile 9 weighs 103 LB
Trash pile 10 is in section1
Trash pile 10 weighs 103 LB
Trash pile 11 is in section1
Trash pile 11 weighs 103 LB
Trash pile 12 is in section1
Trash pile 12 weighs 103 LB
Trash pile 13 is in section1
Trash pile 13 weighs 103 LB
Trash pile 14 is in section1
Trash pile 14 weighs 103 LB"
The numbers change each time I run the program but I would like the output to be different for each trash pile.
I realize the solution is probably simple but I'm 2 hours into this homework and I'm already feeling fried, please help?
(Function for the output shown is as follows)
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void Get_Wigg(wigg w[])
{
int i = 0;
for (i = 0; i < 15; i++)
{
srand(time(NULL));
w[i].sect = (rand()%7+1);
cout << "Trash pile " << i << " is in section" << w[i].sect << endl;
w[i].weight = (rand()%500+25);
cout << "Trash pile " << i << " weighs " << w[i].weight << " LB" << endl;
}
return;
}
| |