Hi.
As the title says I need help with a program I was coding, which is suppose to be an EDF (Earliest Deadline First) Scheduling Algorithm.
This is what I wrote so far (sorry if the program is awful but I'm still learning):
#include<iostream>
usingnamespace std;
class EDF
{
int releasetime;
int executiontime;
int deadlinetime;
int relativedeadline;
int startingtime;
int x[3];
int e[3];
int z[3];
int d[3];
public:
void task_entering();
void task_arrange();
};
void EDF::task_entering()
{
int slack,period;
cout<<"Enter your relative dedline :\n";
cin>>relativedeadline;
for(int i=0;i<3;i++)
{
cout<<"release time is :\n";
cin>>releasetime;
cout<<"deadline time is:\n";
cin>>deadlinetime;
d[i] = deadlinetime;
period = deadlinetime - releasetime;
x[i] = period;
cout<<"execution time is :\n";
cin>>executiontime;
e[i] = executiontime;
slack = deadlinetime - executiontime;
z[i] = slack;
}}
void EDF::task_arrange()
{
int temp,y[3];
for(int j=0;j<=2;j++)
{
y[j]=x[j];
}
for (int j=0; j<2; j++)
{
for(int k = (j+1); k < 3; k++)
{
if (y[j] < y[k])
{
temp= y[j];
y[j] = y[k];
y[k] = temp;
temp= z[j];
z[j] = z[k];
z[k] = temp;
temp= d[j];
d[j] = z[k];
d[k] = temp;
}
}
}
for(int j=2, k=1;j>=0;j--,k++)
{
cout<<"The Task with deadline period of "<<z[j]<<" will be T"<<k<<"\n";
}
int sum = 0;
startingtime = 0;
while(startingtime <= relativedeadline){
for(int j=0;j<=2;j++)
{
if(y[2] == x[j]){
if(d[2] < d[1] && d[2] < d[0]){
if(startingtime <= relativedeadline){
sum = startingtime + e[j];
if(sum >= relativedeadline)
cout<<"("<<startingtime<<"-"<<relativedeadline<<",T"<<j+1<<")\t";
else
cout<<"("<<startingtime<<"-"<<startingtime + e[j]<<",T"<<j+1<<")\t";
startingtime = sum;
d[2] = d[2] * 2;}}}
elseif(y[1] == x[j]){
if(d[1] < d[2] && d[1] < d[0]){
if(startingtime <= relativedeadline){
sum = startingtime + e[j];
if(sum >= relativedeadline)
cout<<"("<<startingtime<<"-"<<relativedeadline<<",T"<<j+1<<")\t";
else
cout<<"("<<startingtime<<"-"<<startingtime + e[j]<<",T"<<j+1<<")\t";
startingtime = sum;
d[1] = d[1] * 2;}}}
elseif(y[0] == x[j]){
if(d[0] < d[1] && d[0] < d[2]){
if(startingtime <= relativedeadline){
sum = startingtime + e[j];
if(sum >= relativedeadline)
cout<<"("<<startingtime<<"-"<<relativedeadline<<",T"<<j+1<<")\t";
else
cout<<"("<<startingtime<<"-"<<startingtime + e[j]<<",T"<<j+1<<")\t";
startingtime = sum;
d[0] = d[0] * 2;}}}
}
}}
main()
{
EDF CPU;
Repeat:
CPU.task_entering();
CPU.task_arrange();
cout<<endl;
goto Repeat;
}
These are the lines:
1 2 3 4 5 6
Line 91: if(d[2] < d[1] && d[2] < d[0])
Line 101: d[2] = d[2] * 2;
Line 106: if(d[1] < d[2] && d[1] < d[0])
Line 116: d[1] = d[1] * 2;
Line 121: if(d[0] < d[1] && d[0] < d[2])
Line 131: d[0] = d[0] * 2;
It's suppose to check if the element of the array is smaller than the others to execute but when I write those lines the program just stop.
------------------
sorry again for my awful coding skills & for being very noob too
You need to fix up your indentation b/c that is not readable so we can't really make sense of what the code is. It could very well be incorrect braces which is causing a logic error but that's hard to see right now.