ok so i have an array like this which contains an id, a myState of type State and pointer next which points to the next id

struct PCB
{
  int id;
  STATE myState;
  Process *next;
};

i have the following function which should decrement all the current values of int by 1

for example if the array has the following {2 3 5}
after calling the function below it should change the array to {1 2 4}

void LL::decrement(int NewNum)
{
  int id;
  int temp;
  PCB *x = front; 
  if(x->id != 1) 
    {
      while(x!= NULL) //while x still not NULL keep doing this
        {
          x->id = temp; // place current value of id into temporary 
          NewNum = temp - 1; // increments temporary and sets it equal to NewNum
          x = x->next; // goes to the next value
        }
    }
}

but after i call it i just get {0 0 0 }

any help on how to fix this?

Well, let's follow your code:

void LL::decrement(int NewNum)
{
  int id;           // create ID with some unknown value
  int temp;         // create TEMP with some unknown value
  PCB *x = front; 
  if(x->id != 1) 
    {
      while(x!= NULL) 
        {
          x->id = temp;      // Load the unknown value TEMP into your structure ID
          NewNum = temp - 1; // Decrement the unknown TEMP value and put it in NewNum
          x = x->next;  
        }
    }
}

When you return, nothing happened to NewNum since you didn't pass the address
x->id got trashed

Looks like you need to think through your process again.
And check out how to do assignment statements.

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.