Click here to Skip to main content
15,867,934 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Help, how can I create a MULTILEVEL QUEUE ALGORITHM program?
I tried it but it crashes, does not build...
It would be okay if its in other language.

HERE IS THE SNIPPET CODE (c++):
C++
//Enter Number of Process (up to 20)
cout<<"\n Enter the number of Processes: ";
cin>>n;


//INPUT Arrival, Burst, and Priority
    cout<<"\n Enter arrival time of process: \n";
    for(i=0;i<n;i++)
    {
    
	  do{
    	
      cout<<"  P"<<i+1<<": ";
	  cin>>a[i];
	  
	  		inputerror = cin.fail();
			if(inputerror)
			{
				cin.clear();
				cin.ignore(1000, '\n');
			}
			cin.sync();
	  
	  		}while((inputerror));
    }
    
    cout<<"\n Enter burst time of process: \n";
    for(i=0;i<n;i++)
    {
    	
      do{
		
      cout<<"  P"<<i+1<<": ";	
      cin>>b[i];
      
      		inputerror = cin.fail();
			if(inputerror)
			{
				cin.clear();
				cin.ignore(1000, '\n');
			}
			cin.sync();
	  
	  		}while((inputerror));
    }
    
    cout<<"\n Enter priority of process (1-FP/2-BP):  \n";
    for(i=0;i<n;i++)
    {
    	
      do{
	  
      cout<<"  P"<<i+1<<": ";
      cin>>p[i];
      
      		inputerror = cin.fail();
			if(inputerror)
			{
				cin.clear();
				cin.ignore(1000, '\n');
			}
			
			cin.sync();
	  
	  		}while((inputerror));
    }


//Enter Algorithm
    cout<<endl;
    cout<<" Algorithm: "<<endl
		<<"  [1] FCFS"<<endl
		<<"  [2]SJF-P"<<endl
		<<"  [3]SJF-NP"<<endl
		<<"  [4]P-P"<<endl
		<<"  [5]P-NP"<<endl
		<<"  [6]RR"<<endl
		<<" -------------"<<endl;
     
	 do{
	  
      cout<<" Enter Alogrithm Number: ";
      cin>>algo;
      
      		inputerror = cin.fail();
				if(inputerror)
				 {
				 	cin.clear();
					cin.ignore(1000, '\n');
				 }
				else if (algo<1)
				 {
				 	cin.clear();
					cin.ignore(1000, '\n');
				 }
				 else if (algo>6)
				 {
				 	cin.clear();
					cin.ignore(1000, '\n');
				 }
				 
				 cin.sync();
	  
	  		}while((inputerror)||(algo<1)||(algo>6));
    

//Other Values
    do{
	  
      cout<<" Foreground Process: ";
      cin>>forground_process;
      
      		inputerror = cin.fail();
			if(inputerror)
			{
				cin.clear();
				cin.ignore(1000, '\n');
			}
			
			cin.sync();
	  
	  		}while((inputerror));
	  		
	do{
      
      
      cout<<" Quantum: ";
      cin>>quantum;
      
      		inputerror = cin.fail();
			if(inputerror)
			{
				cin.clear();
				cin.ignore(1000, '\n');
			}
			
			cin.sync();
	  
	  		}while((inputerror));
	  		
	do{
	  
      cout<<" Background Process: ";
      cin>>background_process;
      
      		inputerror = cin.fail();
			if(inputerror)
			{
				cin.clear();
				cin.ignore(1000, '\n');
			}
			
			cin.sync();
	  
	  		}while((inputerror));


/* I DON'T KNOW HOW TO SHOW THIS, HELP...

Gantt Chart
  <Gantt Chart here>

Table
  <Populated Table>

TAT Total: ?
TAT Average: ?
WT Total: ?
WT Average: ? 

*/

repeatConfirm();


What I have tried:

Coding in C++ but it crashes, does not build...
Posted
Updated 18-Jun-20 19:59pm
Comments
Rick York 18-Jun-20 21:29pm    
If it does not build then it can not possibly crash. You have to build it before it can run.

As a wild guess, make sure a, b, and p have a size bigger than the value n. If they are vectors are they initialized? If not then use push_back to save the values.
Patrice T 18-Jun-20 23:21pm    
Give error messages!
We can't compil your code snipset

1 solution

If that is your entire code, then no, it won't build: you are missing the #include statements, any using lines, and a function definition for that code to run in: the minimum C++ program is pretty much this:
C++
#include <iostream>
using namespace std;

int main()
    {
    cout<<"Hello World";
    return 0;
    }

And even if you gave us the complete error messages that the compiler generates when you try to build the app, it wouldn't help much without that actual framework in place.

So it's going to be up to you.
Start by looking at the compiler error messages: they will be of the form
C++
Filename.cpp:Line number:Column number: Message
For example:
main.cpp:17:5: error: expected ‘;’ before ‘return’
That is saying that "main.cpp" has a problem on line 17, column 5: there is a missing semicolon before the line of code starts.
So use your editor to go to the appropriate line and look at the code and what is immediately above it.

Do that with your error messages and most of them should be pretty obvious: if they aren't then ask again but this time show us the relevant fragments, complete with the error message, and indicate what line the error is showing up on.

We can't fix compilation problems with code we can't compile!
 
Share this answer
 
Comments
Member 14867174 19-Jun-20 6:22am    
I literally know that, my question is below the snippet code.
OriginalGriff 19-Jun-20 6:56am    
Which will not compile or run.
And until it does, there is nothing to "explain" - it's pointless to try and talk about code that doesn't compile cleanly.

Think of it as teaching someone to drive: if the car is missing half the engine, two wheels, and the drivers seat you can't really learn much. You need to fix the car before you can start giving lessons!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900