有人能检查并修复我的代码吗?我面临以下错误: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
//日程安排使用系统;
公共类测试{
// 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 timen");
// 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( );
虽然我认为你想阅读一个特定的密钥,所以试试:
var run = Console.ReadKey( );
while ( run.Key == ConsoleKey.Y );
我还注意到,在do while
循环条件中使用的是赋值运算符=
,而不是比较运算符==
。
我忘记在循环中添加for关键字。