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.