Question: C++ help! Hey! I'm having trouble executing my while loop for reading a file. It doesn't end and my getline isn't reading the next 5

C++ help!

Hey! I'm having trouble executing my while loop for reading a file. It doesn't end and my getline isn't reading the next 5 increments. Here is my code, input file, and error below. Thank you so much!!

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

//

// Returns 'true' if a customer arrived during this minute, using

// a random number.

//

bool customerArrived(double prob) {

double rv = rand() / (double(RAND_MAX) + 1);

return (rv

}

struct Customer {

int arrivalTime; // time customer arrived

int serviceTime; // time required for service

};

/* Main program */

int main() {

string simName;

int simTime;

int serviceTime;

int maxLineSize;

double arrivalRate; // per-minute arrival rate of customers

ifstream f("simtest.txt");

if (!f){

cout

return 1;

}

// seed random number generator

srand(time(0));

//simulation loop

getline(f, simName);

f >> simTime >> arrivalRate >> serviceTime >> maxLineSize;

while (!f.eof()){

//simulation variables

int totalCustomers = 0;

int totalDropped = 0;

int currentTime = 0;

int currentLineLength = 0;

int totalWait = 0;

queue line;

while (currentTime

// check if customer arrives

if (customerArrived(arrivalRate)){

if(currentLineLength

Customer c = {currentTime, serviceTime};

c.arrivalTime = currentTime;

line.push(c);

currentLineLength++;

} else {

totalDropped++;

}

}

// checks if the cashier is free, serve the next person

if(!line.empty()){

Customer c = line.back();

if((currentTime - c.arrivalTime) >= c.serviceTime){

totalCustomers++;

totalWait += (currentTime + c.serviceTime) - c.arrivalTime;

line.pop();

currentLineLength--;

}

}

currentTime++;

//totalWait++;

}

//output simulation results

// Left-justify everything

cout

// Print a table

cout

cout

cout

cout

cout

cout

cout

cout

cout static_castdouble>(totalWait)/totalCustomers

cout

double(totalWait)/simTime

cout

cout

getline(f, simName);

f >> simTime >> arrivalRate >> serviceTime >> maxLineSize;

}

return 0;

}

input file:

Short Lines 2000 0.1 15 5 Long Lines 2000 0.5 15 10 Mixed 2000 0.25 8 7 here's what i got:

C++ help! Hey! I'm having trouble executing my while loop for readinghere's what it's supposed to look like for one simulation (w/o the loop):

Simulation name: Short Lines -------------------------------------- Simulation time: 2000 Arrival rate: 0.1 Service time: 15 Max line size: 5 Customers served: 125 Average wait time: 66.688 Average line length: 4.246 Total dropped customers: 97

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!