Question: Hi I need help with my code. so it doesnt allow me to input any number nor does it display the turnaround time and the

Hi I need help with my code. so it doesnt allow me to input any number nor does it display the turnaround time and the waiting time. Can you please help me? #include
#include
#include
#define EXIT 0
#define INVALID -1
#define CPU 1
#define PID 5
// Function prototypes
int displayMenu();
void cpuScheduling();
void fcfs(int process[], int at[], int bt[]);
void sjf(int process[], int at[], int bt[]);
void displaySchedule(int process[], int at[], int bt[], int wt[], int tat[]);
int main(){
int choice = INVALID;
// Main loop
while (choice != EXIT){
choice = displayMenu();
// Execute CPU scheduling functionality for choice CPU
if (choice == CPU){
cpuScheduling();
}
// Exit the program if choice is EXIT
else if (choice == EXIT){
exit(EXIT_SUCCESS);
}
}
return 0;
}
// Function to display the OS Management Menu and get user's choice
int displayMenu(){
int choice = INVALID;
// Display the OS Management Menu
printf("
OS Management Menu
");
printf("1. CPU Scheduling
");
printf("0. Exit
");
// Prompt user for choice and validate
do {
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice < EXIT || choice > CPU){
printf("Invalid choice. Please enter a valid choice.
");
choice = INVALID;
}
} while (choice == INVALID);
return choice;
}
// Function to perform CPU scheduling
void cpuScheduling(){
// Fixed data for processes (as per the assignment)
int process[5]={1,2,3,4,5};
int at[5]={0,2,4,6,7};
int bt[5]={8,5,10,2,3};
// Perform FCFS and SJF scheduling
fcfs(process, at, bt);
sjf(process, at, bt);
}
// First-Come, First-Served scheduling algorithm
void fcfs(int process[], int at[], int bt[]){
// Calculate waiting times and turnaround times for FCFS
int wt[5], tat[5];
wt[0]=0;
for (int i =1; i <5; i++){
wt[i]= bt[i -1]+ wt[i -1]- at[i];
if (wt[i]<0){
wt[i]=0;
}
}
for (int i =0; i <5; i++){
tat[i]= bt[i]+ wt[i];
}
// Display schedule and statistics for FCFS
displaySchedule(process, at, bt, wt, tat);
}
// Shortest Job First scheduling algorithm
void sjf(int process[], int at[], int bt[]){
// Sort processes based on burst time for SJF
for (int i =0; i <4; i++){
for (int j =0; j <4- i; j++){
if (bt[j]> bt[j +1]){
// Swap burst times
int temp = bt[j];
bt[j]= bt[j +1];
bt[j +1]= temp;
// Swap process IDs
temp = process[j];
process[j]= process[j +1];
process[j +1]= temp;
// Swap arrival times
temp = at[j];
at[j]= at[j +1];
at[j +1]= temp;
}
}
}
// Calculate waiting times and turnaround times for SJF
int wt[5], tat[5];
wt[0]=0;
for (int i =1; i <5; i++){
wt[i]= bt[i -1]+ wt[i -1]- at[i];
if (wt[i]<0){
wt[i]=0;
}
}
for (int i =0; i <5; i++){
tat[i]= bt[i]+ wt[i];
}
// Display schedule and statistics for SJF
displaySchedule(process, at, bt, wt, tat);
}
// Function to display schedule and statistics
void displaySchedule(int process[], int at[], int bt[], int wt[], int tat[]){
// Display schedule and statistics
printf("
Process\t Arrival Time\t Burst Time\t Waiting Time\t Turnaround Time
");
for (int i =0; i <5; i++){
printf("%d\t %d\t\t %d\t\t %d\t\t %d
", process[i], at[i], bt[i], wt[i], tat[i]);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!