#include<iostream>
#include<cstdlib>
#include<fstream>


using namespace std;
int main()
{   int n=3;
    float total,wait[3]={0};
    float p[3],twaiting=0,waiting=0;
    int proc;
    int stack[3];
    float burst[3],arrival[3],sburst,temp[3],top=3;

for(int i=0;i<n;i++)
    {
        p[i]=i;
        stack[i]=i;
        cout<<"Enter arival time : ";
        cin>>arrival[i];
        cout<<endl<<"Enter burst time: ";
        cin>>burst[i];
        temp[i]=arrival[i];
        sburst=burst[i]+sburst;

    for(i=0;i<sburst;i++)
    {
        proc=stack[0];
        if(temp[proc]==i)
        {
            //temp[proc]=i+1;;
            twaiting=0;
        }
        else
        {
            twaiting=i-(temp[proc]);

        }
        temp[proc]=i+1;

        wait[proc]=wait[proc]+twaiting;
        waiting=waiting+(twaiting);
         burst[proc]=burst[proc]-1;
            if(burst[proc]==0)
        {
            for(int x=0;x<top-1;x++)
            {
                stack[x]=stack[x+1];
             }
            top=top-1;
            for(int z=0;z<top-1;z++)
            {
                 if((burst[stack[0]]>burst[stack[z+1]]) && (arrival[stack[z+1]] <= i+1))

                       int t=stack[0];
            stack[0]=stack[z+1];
            stack[z+1]=t;
              }
          }
        }

cout<<"waiting:"<<waiting;
return 0;
    }
    }
}

There is a little problem at line 57. It says that the t is nt declared. I assume it that i need to insert a header file like <stdlib>.Please help me

take another look of the if statement 
it only takes one command and whatever was declared in it is destroyed
and gone, cant be approached from the outside of the scope.

if you want all 3 commands to be performed together just add {}

and if you want only the t to be changed and that it could be approached from the
outside just declare it before the IF statement
and update its valure inside of it

thx.okey i solved it already...but now im having trouble..the thing continued to asking me the same thing in a loop..it doesnt end....Help me with me..

your first loop has "i" and the second loop has "i" also
could be it

if i change to the i to j in the second loop..its ends after taking 1 input only..i need to tk 3 input n show 3 input asnwer

you have many uninitialized values that you should fix.
also does the program works fine for you?
because there are illegal calls - segmentation faults
at the IF statement.
try working with a debugger and go slowly , checking if everything you try to
reach should be reached.

What happens when you sit at your desk with the code, pencil, and paper and actually follow the program line by line? Writing the variable values as they change?

but for your last question , look at the return 0 you have at the end
well its NOT in the end, you put it at the end of the loop instead outside of it
and init the variables at the top:

int n=3;
float total=0,wait[3]={0};
float p[3]={0},twaiting=0,waiting=0;
int proc=0;
int stack[3]={0};
float burst[3]={0},arrival[3]={0},sburst=0,temp[3]={0},top=3;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.