c# - 使用 C# 的先到先服务 (FCFS) CPU 调度错误

标签 c# loops syntax-error user-input

有人可以检查并修复我的代码吗,我面临以下错误:
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:意外符号“字符”
编译失败:5 个错误,0 个警告
编译器退出状态 1
我的代码:

// C# program for implementation of FCFS 
//调度
使用系统;
公开课测试
{
// 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关键词。
另外,Console.ReadLine( )返回 string不是 char .
应该:string run = Console.ReadLine( );或者var run = Console.ReadLine( );尽管我认为您想阅读特定的 key ,但请尝试:

var run = Console.ReadKey( );
while ( run.Key == ConsoleKey.Y );
我还注意到您正在使用赋值运算符 =而不是比较运算符 ==在您的 do while循环条件。

关于c# - 使用 C# 的先到先服务 (FCFS) CPU 调度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65046167/

相关文章:

c# - C#中高速切换位

c# - iTextSharp 像 PDF24Creator 一样改变结果质量/压缩

java - 使用 while 循环验证输入

尝试放置文字哈希时出现 Ruby 语法错误

parsing - Bison语法错误处理

c# - 自终止 自托管 WebAPI

c# - 当传入串口的数据是异步的时,如何通过 Web 服务存储数据?

C# 遍历类属性

JavaScript 无限 For 循环

sql - 无法弄清楚为什么R中的sqldf出现 “from”附近的语法错误