this code is correct expect that part which calculate the waiting time .. it should be 0 in first process but in output it equals the burst time of 1st process. how can i fix it ?
#include <iostream>
#include<iomanip>
#include<queue>
using namespace std;
int main(){
queue<int> sc;
float tat = 0, total_tat = 0, tw=0, total_tw = 0; //tat: turnaround time , tw: waiting time
int n = 0,i,j, bt = 0;//bt: burst time -time to start-
cout << "enter number of processes : " << endl;
cin >> n;
cout << "\n enter process working time :"<<endl;
for (i = 0; i < n; i++){
cout << "p[" << i+1 << "]:";
cin >> bt;
sc.push(bt);
}
cout << "\n process "<<setw(3)<<" burst time"<<setw(15)<<"waiting time"<<setw(19)<<"turnaround time";
for (j = 0; j < n; j++){
bt = sc.front();
tw = tw + bt; //here is the problem
tat = bt + tw;
total_tw = total_tw + tw;
total_tat = total_tat + tat;
cout << "\n p[" << j +1 << "]" << setw(7) << bt << setw(17) << tw<< setw(20) << tat;
sc.pop();
}
cout << "\n average waiting time : " << total_tw / n << endl;
cout << "average turnaround time : " << total_tat / n << endl;
return 0;
}