Please help me with this code

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):
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include<iostream>
using namespace 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;}}}


        else if(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;}}}


        else if(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
Last edited on
What problem are you having?

Please edit your post, highlight the code and click on the code format tag (the <> button.
Thanks for the advice, I just fixed the post.
But about the code, can someone help please ?
Last edited on
Anyone ?
so much for my first post here
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.

Also, why do you need to use goto in main()?
I think it's readable now.
I used goto just for eternal looping. I can replace it with for(;;)
Topic archived. No new replies allowed.