0

I'm posting this question for the second time (because no one helped me the first time). So, I need your help with a Round Robin program. When I wanted to calculate waiting time for each Process, I got confused, I didn't know what to do, I didn't know how to calculate waiting time . I tried to use different logics, but I failed everytime.

I need your help to calculate waiting time .

This is my Source Code.

#include<iostream>
using namespace std;

int main()
{
int BT[10], TQ, start=0, stop=0, counter=0, check=0;

cout << " Enter Time Qunatem : "; cin >> TQ;
cout << "\n How many Processes do you want? (10 is Maximum) " ; cin >> counter;

cout << "\n\n Enter Burst Time for each Process : " << endl;

for(int i = 0; i < counter; i++ )
{ cout << " P" << i+1 << " = " ; cin >> BT[i]; }

cout << "\n\n";


for( int i = 0; i < counter; i++ )
{
    if(BT[i] > 0)
    {

        if( TQ <= BT[i] )
        {

            cout << " P" << i+1 << " = ";
            BT[i] = BT[i] - TQ;
            start = stop;
            stop = stop + TQ;

            cout << BT[i] << " | Starts at : " << start << " | Stops at : " << stop << endl;


        }

        else if( TQ > BT[i] )
        {
            cout << " P" << i+1 << " = ";
            start = stop;
            stop = stop + BT[i];

            cout << BT[i] << " | Starts at : " << start << " | Stops at : " << stop << endl;

            BT[i]=0;

        }

    }


    if (i == counter-1)
    {
            for( int j = 0; j < counter; j++ )
            {
                check=check+BT[j]; 

                if (j == counter-1)
                {
                    if (check <= 0)
                    { cout << " ARRAY IS EMPTY\n"; break; }
                    else
                    { cout << " ARRAY IS NOT EMPTY\n"; i=-1; }
                }
            }
    }

    check=0;

}

cout << "\n\n\n\n";

return 0;

}

So, could you help me to calculate waiting time for each process...?

You should use http://cpp.sh/ to run this code online.

  • 1
    Please trim your code and refine your question to be more specific. Right now it has a lot of stuff we don''t need. – therainmaker Nov 12 '15 at 18:17
  • @therainmaker I don't understand what you mean with trimming my code? I thought I should give you my whole code so that you can understand my style of coding. Sorry if it bothers you. –  Nov 12 '15 at 18:18
  • 2
    Right now all you've told us is that you've created the code for a `Giant Chart` (means nothing to me). You want to calculate waiting time for process and total waiting time. Total time divided by number of processes seems fine. Why not do that? Whatever the reason is for that, its obfuscated. Next, you say you got confused and don't know what to do. What exactly (like which part) did you get confused in.Throwing a big piece of code at us won't help much. – therainmaker Nov 12 '15 at 18:21
  • @therainmaker Thanks for your reply. It shows that you had the intention to help me. It's just the calculation of waiting time that is holding me back. I just want help with how to calculate WAITING TIME (I know how to calculate it in real life, but I don't know how to calculate it in `C++`). You wanna help me or mock me? :) –  Nov 12 '15 at 18:31
  • 1
    I'm not trying to mock you. I'm trying to help you, and others who are gonna be looking at this question. We aren't here just to solve your problems, but also to help you learn how to solve them on your own. Coming back. What is the waiting time defined as? If you have total time and number of processes, why not divide them. Give more information on this. – therainmaker Nov 12 '15 at 18:35
  • @therainmaker Sorry, for the confusion. I can't calculate TOTAL WAITING TIME until I calculate waiting time for each process. calculating waiting time for each process is where my problem is showing. –  Nov 12 '15 at 18:44

1 Answers1

0

Try reading through the following: How to Calculate Execution Time of a Code Snippet in C++

ctime is extremely useful, and I have a good feeling you will use it in a multithreading case in the future.

Community
  • 1
  • 1
Adolphin
  • 62
  • 4