Need help! (for loops/random number generator)

I'm having trouble with running for loops inside for loops. For my assignment I have a bunch of calculations that need to be ran a certain amount of times (specified by user). The problem I'm having is that my Trial outputs are all the same and thus the average is the same as all the trials. I think the calculations aren't looping correctly. Any help is greatly appreciated, thank you.
This is my code:

/*
10/15/14
*/

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

// Defining Constants

const int servet = 2; // Server Efficency Time
const double customerorder = .75; // Customer Ordering Time
const double seatingmax = 2.5; // Seating Time (max)
const int partymax = 10; // Max ammount of people in one party

int main()
{
// Defining Variables
srand(time(0));
int arrivalmax = 30; // Max arrival seating time
int servingfood = servet; // Time for server to get dinner to table
int servingdesert = servet; // Time for server to get desert to table
int serverarrival = servet; // Time for server to arrive to table off the start
int partysize = rand() % (partymax - 1) + 1; // Party size
int foodtime = rand() % (25 - 10) + 10; // Time to cook each meal.
int dessert = rand() % (partymax - 1) + 1; // Amount of people ordering desert.
int desserttime = rand() % (25 - 10) + 10; // Time too cook dessert
double arrivalseat = rand() % arrivalmax; // Time expended waiting for a seat
double waitforfoodtime = rand() % (25 - 10) + 10; // Time expended waiting for dinner to cook
double endmeal = rand() % (20 - 10) + 10; // Time expended after desert is served
double eatingtime = rand() % (40 - 20) + 20; // Time expended eating
double ordertime = partysize*customerorder; // Time it takes for all the customers to order.
double desserttotal = dessert*customerorder; // Time expended ordering desert.
double step3 = servet + ordertime; // Server constant + ordering time
double sum = 0;
double parties = 0;
double c = 0;
double avg = 0;
double i = 0;
double max = 0;
double b = 0;
double max2 = 0;
max2 = desserttime;
max = foodtime;
foodtime = rand() % (25 - 10) + 10;
desserttime = rand() % (25 - 10) + 10;
// Final time calculation
double finaltime = arrivalseat + seatingmax + step3 + max + servet + eatingtime + max2 + servet + endmeal;
double final2 = finaltime;
double a = 0;

cout << " How many total parties are there? " << endl;
cin >> parties;

for (c = 1; c <= parties; c++)
{
for (a = 0; a <= parties; a++)
{
for (i = 0; i < partysize; i++)
{
if (foodtime > max)
max = foodtime;
}
for (b = 0; b < partysize; b++)
{
if (desserttime > max2)
max2 = desserttime;
}

arrivalseat = rand() % arrivalmax;
step3 = servet + ordertime;
eatingtime = rand() % (40 - 20) + 20;
endmeal = rand() % (20 - 10) + 10;
finaltime = arrivalseat + seatingmax + step3 + max + servet + eatingtime + max2 + servet + endmeal;
finaltime = final2;
}
cout << "Trial " << c << ": " << final2 << " minutes." << endl;
sum += final2;
}


avg = sum / parties;

cout << "Average dining time among all parties in simulation: " << avg << endl;

system("pause");
return 0;

}



Last edited on
Topic archived. No new replies allowed.