先来先服务 (FCFS) CPU 使用 C# 安排时出错

Error in First Come First Serve (FCFS) CPU Scheduling using C#

有人可以检查并修复我的代码吗,我遇到了以下错误: main.cs(80,10): 错误 CS1525: 意外的符号 =', expecting ,' main.cs(80,25):错误 CS1525:意外符号 )', expecting ;'或 }' main.cs(89,10): error CS1525: Unexpected symbol =',期待 ,' main.cs(89,25): error CS1525: Unexpected symbol )',期待 ;' or }' main.cs(96,3):错误 CS1525:意外的符号“char” 编译失败:5 个错误,0 个警告 编译器退出状态 1

我的代码:

// C# program for implementation of FCFS 

// 调度 使用系统;

public class 测试 {

// Function to find the waiting time for all 
// processes 
 public static void findWaitingTime(int []processes, int n, 
                            int []bt, int[] wt) 
{ 
    // waiting time for first process is 0 
    wt[0] = 0; 

    // calculating waiting time 
    for (int i = 1; i < n; i++) 
    { 
        wt[i] = bt[i - 1] + wt[i - 1]; 
    } 
} 

// Function to calculate turn around time 
public  static void findTurnAroundTime(int []processes, int n, 
        int []bt, int []wt, int []tat) { 
    // calculating turnaround time by adding 
    // bt[i] + wt[i] 
    for (int i = 0; i < n; i++) 
    { 
        tat[i] = bt[i] + wt[i]; 
    } 
} 

// Function to calculate average time 
    public  static void findavgTime(int []processes, int n, int []bt) 
{ 
    int []wt = new int[n]; 
    int []tat = new int[n]; 
    int total_wt = 0, total_tat = 0; 

    //Function to find waiting time of all processes 
    findWaitingTime(processes, n, bt, wt); 

    //Function to find turn around time for all processes 
    findTurnAroundTime(processes, n, bt, wt, tat); 

    //Display processes along with all details 
    Console.Write("Processes Burst time Waiting"
                +" time Turn around time\n"); 

    // Calculate total waiting time and total turn 
    // around time 
    for (int i = 0; i < n; i++) 
    { 
        total_wt = total_wt + wt[i]; 
        total_tat = total_tat + tat[i]; 
        Console.Write(" {0} ", (i + 1)); 
        Console.Write("  {0} ", bt[i]); 
        Console.Write("  {0}", wt[i]); 
        Console.Write("  {0}\n", tat[i]); 
    } 
    float s = (float)total_wt /(float) n; 
    int t = total_tat / n; 
    Console.Write("Average waiting time = {0}", s); 
    Console.Write("\n"); 
    Console.Write("Average turn around time = {0} ", t); 
} 

// Driver code 
public static void Main(String[] args) 
{ 
    do{
        
    // input process 
    int[] processes = new int[100]; 
    Console.WriteLine("How many process? MAX = 100 ");
    int n = Convert.ToInt32(Console.ReadLine());

    //generate process id
    ( int i = 0; i < n; i++){

         processes[i] = i + 1;

}

    // input Burst time
    int[] burst_time = new int[100];
    Console.WriteLine("Input burst time: ");
    ( int i = 0; i < n; i++){
        burst_time[i] = Convert.ToInt32(Console.ReadLine());
    }
        
                findavgTime(processes, n, burst_time); 
        
        Console.WriteLine("Run Again? [Y/N] ")
        char run = Console.ReadLine();
    }
    while(run = Y);

} 

}

我的来源: https://www.geeksforgeeks.org/program-for-fcfs-cpu-scheduling-set-1/

只是想添加用户输入,例如进程数和突发时间。

我忘了在循环中添加 for 关键字。

您已经注意到,您缺少 for 关键字。 另外,Console.ReadLine( ) returns 是 string 而不是 char.

应该是:

string run = Console.ReadLine( );

var run = Console.ReadLine( );

虽然我认为你想读取特定的键所以尝试:

var run = Console.ReadKey( );
while ( run.Key == ConsoleKey.Y );

我刚刚还注意到您在 do while 循环条件中使用了赋值运算符 = 而不是比较运算符 ==