I have and infinite loop and i dk where the error is

#include <string>
#include <queue>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <iterator>
#include <list>

using namespace std;
void remove(int list[], int listLength, int removeItem);

struct Vehicle {
int id;
int priority;
int resource_utilization;
};

class CompareVehicle {
public://this creates two vehicle objects and compares their properties and sets their places in the queue
bool operator() (Vehicle& v1, Vehicle& v2) {
if(v1.priority < v2.priority) return true;
return false;
}
};

//global variables
int num1[20], num2[20], num3[20], num11[20], num21[20], num31[20];

//for now numbers will be fixed
priority_queue<Vehicle, vector<Vehicle>, CompareVehicle> pq;
//array of car objects with first value being process id second is priority and third being resource_utilization
// Vehicle c [3] = {{56, 1, 2}, {19, 9, 45}};

//car lot array of vehicle type to hold cars by priority
Vehicle temp[10] = {};
int lot[10] = {};
unsigned int i;
list<unsigned int> my_lot;
list<unsigned int>::iterator it1,it2;
//temp counter
int t=0;
int idk = 0;
int free_space = 0;
int length = 10;
//end of global variables



void gen_rand() {
cout<<"All vehicles that came in"<<endl;
for(int i=0; i<10; ++i) {
num1[i] = rand() % 1000 + 1;//generate a random process ID 1 - 1000
num2[i] = rand() % 10 + 1;//generate a random priority 1 - 10
num3[i] = rand() % 6000 + 10000;//generate a random resource_utilzation amount 1 - 30
cout<<num1[i]<<setw(3)<<" "<<num2[i]<<setw(3)<<" "<<num3[i]<<endl;
}//end for
}//end gen_rand

void gen_again() {
idk = rand() % 4 + 1;

for(int i = 0; i<idk; i++) {
num1[i] = rand() % 1000 + 1;//generate a random process ID 1 - 1000
num2[i] = rand() % 10 + 1;//generate a random priority 1 - 10
num3[i] = rand() % 6000 + 10000;//generate a random resource_utilzation amount 1 - 30
cout<<num1[i]<<setw(3)<<" "<<num2[i]<<setw(3)<<" "<<num3[i]<<endl;
}//end for

}//end gen again

int gen_decide() {
int decide = rand() % 2 + 1;

return decide;
}


void requeue() {
for(int i=0; i < idk; i++) {
Vehicle c[5] ={{num1[0], num2[0], num3[0]}, {num1[1], num2[1], num3[1]}, {num1[2], num2[2], num3[2]},
{num1[3], num2[3], num3[3]}, {num1[4], num2[4], num3[4]}};
pq.push(c[i]);
//Vehicle v2 = pq.top();
temp[t] = pq.top();//all values still stored in temp array
//cout<<v2.id<<" "<<v2.priority<<" "<<v2.resource_utilization<<endl;
//pq.pop();
}

}

void run() {
while(!pq.empty()) {//needs more logic
Vehicle v2 = pq.top();
// cout<<v2.id<<" "<<v2.priority <<" "<<v2.resource_utilization<<endl;

cout<<"Vehicle "<<v2.id<<" has a priority of " <<v2.priority<<" and will now enter the car park"<<endl<<endl;

lot[t] = v2.id; //copy vehicle to lot then pop it off main list
//lot[t].priority = v2.priority;

my_lot.push_back(v2.id);
it1 = it2 = my_lot.begin();

pq.pop();//take vehicle off list



t++;

}//end while

cout<<"Cars currently in the lot"<<endl;


//view_lot();
//----------------------------------------
// cout<<pq.size()<<endl;//last car in lot was not removed
//cout<<"new cars waiting "<<endl;


}

void decision() {
int count=0;
int what_to_do = gen_decide();

if(what_to_do == 1) {//add car
gen_again();
requeue();

while(!pq.empty()) {
Vehicle v2 = pq.top();
cout<<"Vehicle "<<v2.id<<" has a priority of " <<v2.priority<<" and will now enter the car park"<<endl<<endl;
my_lot.push_back(v2.id);
//it1 = it2 = my_lot.begin();

pq.pop();//take vehicle off list

decision();

}//end while
}//end if

else {//remove cars from list

int remove_item = rand() % 10 + 1;
advance(it1, remove_item);
it1 = my_lot.erase(it1);
cout<<"vehicle on lot "<<remove_item<<" has finished"<<endl;




cout << endl;
for(it1 = my_lot.begin(); it1!=my_lot.end(); ++it1){
count++;
cout<<"Cars on lot now are "<<*it1<<" on "<<count<<endl;
}//end for
decision();


}//end else

}//end decision function

void run_after() {

while(!pq.empty()) {//needs more logic
Vehicle v2 = pq.top();
cout<<"Vehicle "<<v2.id<<" has a priority of " <<v2.priority<<" and will now enter the car park"<<endl<<endl;
//lot[t] = v2.id; //copy vehicle to lot then pop it off main list
my_lot.push_back(v2.id);
//it1 = it2 = my_lot.begin();

pq.pop();//take vehicle off list



t++;

//cout << "That size exceeds the limit.\n";
decision();
//break;

}//end while



}

void enqueue() {//push first ten cars onto queue
for(int i=0; i < 10; i++) {
Vehicle c[10] ={{num1[0], num2[0], num3[0]}, {num1[1], num2[1], num3[1]}, {num1[2], num2[2], num3[2]},
{num1[3], num2[3], num3[3]}, {num1[4], num2[4], num3[4]}, {num1[5], num2[5], num3[5]},
{num1[6], num2[6], num3[6]}, {num1[7], num2[7], num3[7]}, {num1[8], num2[8], num3[8]},
{num1[9], num2[9], num3[9]}
};
pq.push(c[i]);
//Vehicle v2 = pq.top();
temp[t] = pq.top();//all values still stored in temp array
//cout<<v2.id<<" "<<v2.priority<<" "<<v2.resource_utilization<<endl;
//pq.pop();
}
}








int main() {

//initialize random number seed
srand (time(NULL));



gen_rand();

enqueue();

cout<<" "<<endl;
run();
decision();


// }


//-----------------------------------------------

return 0;

/*
//takes the highest integer and places it to the top of the queue, "top" does not
//remove the element it just returns it
priority_queue<int> pq;

pq.push(1);
pq.push(3);
pq.push(2);

while (!pq.empty()) {
cout<<pq.top()<<endl;
pq.pop();
}//end while

return 0;
*/
}


decision() is infinite recursive.
ok cool, thank you can u help me fix it im not that strong in c++
If you're going to use recursion, you need to have some condition within your recursive function that stops it calling itself again.

Under what condition should your function stop recursing?
decision decides if to generate more cars, how much more their priority or if to remove cars from the lot
I didn't quite understand that, but I'll rephrase my question:

When do you want decision to stop calling itself?

What should make it stop calling itself?
Topic archived. No new replies allowed.