Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
what the result of average_time have negative
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Robert, post: 3046277"] I fix the bug by myself. the main.cpp change as bellow: while (average_wait > 1) { perhour = rand() % 50 + 1; min_per_cust = MIN_PER_HR / perhour; line_wait = 0; for (long cycle = 0; cycle < cyclelimit; cycle++) { if (newcustomer(min_per_cust)) { if (line.isfull()) turnaways++; else { customers++; temp.set(cycle); line.enqueue(temp); } } if (wait_time <= 0 && !line.isempty()) { line.dequeue(temp); wait_time = temp.ptime(); line_wait += cycle - temp.when(); if (line_wait < 0 ) { cout << "line_wait overfolw " << endl; break; } served++; } if (wait_time > 0) wait_time--; sum_line += line.queuecount(); } while (!line.isempty()) line.dequeue(temp); if (served) { if ( line_wait < 0 || served < 0 ) int t = 100; average_wait = (double)line_wait / served; cout << " line wait: " << line_wait << endl; cout << " customers served: " << served << endl; cout << " average wait time: " << average_wait << "minutes\n"; } //cout << " average wait time: " << average_wait << endl; served = 0; turnaways = 0; sum_line = 0; wait_time = 0; line_wait = 0; } if (customers > 0) { cout << "customers accepted: " << customers << endl; cout << " customers served: " << served << endl; cout << " turnaways: " << turnaways << endl; cout << "average queue size: "; cout.precision(2); cout.setf(ios_base::fixed,ios_base::floatfield); cout.setf(ios_base::showpoint); cout << (double) sum_line / cyclelimit << endl; cout << " average wait time: " << average_wait << "minutes\n"; cout << "the average number of customers per hour" << perhour << endl; } else cout << "No customers!\n"; } } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
what the result of average_time have negative
Top