Help Simulating Software buffer scenarios

Hi... So, I'm taking an Architecture & OS class and wasn't really prepared to do any programming for it, but I have a lab that requires me to write a bit of software to simulate the effect that buffers have on looped processing time.

To be clear: I am not looking for someone to do my homework for me. I want to learn this, so I would just like some tips on how to improve my code, if anyone can help.

Here's the assignment:
Assume the following:
a. Disk spooling is NOT being used.
b. The printer does NOT have a hardware buffer to hold the output while the printer is printing

SIMULATE the following scenario
A hypothetical program computes for three seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator)
The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer.


And here's the code I have so far. (This is in a for loop that runs it 500 times and I am just manually changing the maxArray value to try for different buffer sizes until I get it working properly).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
   int x = 0;
        while (x < arrayMax)
        {
        timeCount += calcTime;              // 3 Seconds added to running time
        randNum = rand() % (476 - 75) + 75; // Random number between 75 and 475 is calculated
        calcValue = randNum / 100;          // That number is divided by 100 and assigned to calcValue
        
        if (printer == 0.0)                 // Checks for available printer
        { printer = calcValue; }            // If it's available, it is printed
        
        else
            while (x < arrayMax)            // Otherwise, it staerts checking the array
            {
                if (buffer[x] == 0)
                {
                    buffer[x] = calcValue;
                    break;
                }
                else x++;
            }
        }
        
        if (x == arrayMax)                  // x can only == arrayMax if the buffer is full
        { timeCount += printer;             // If the buffer is full, the print time is added to the total running time.
            for (int y = 0; y < x; y++)
            {
                buffer[y] = buffer[y+1];    // Buffer positions are moved up.
            }
            buffer[x] = 0.0;                // Last buffer in line is set to empty
            x = 0;                          // x is reset to 0.
        }
        
        
        x = 0;


If anyone can offer any assistance, I would greatly appreciate it.
Topic archived. No new replies allowed.