Can someone please help me translate my pseudocode below into C# code? I am tryi
ID: 3569523 • Letter: C
Question
Can someone please help me translate my pseudocode below into C# code? I am trying to solve the following problem: There are eight cars in each team called Chevy and Ford. One car from each team races its opponent on the drag strip. Read in the racing times for the eight Chevy cars, and then read in the times for the eight Ford cars. Store the times into arrays called Chevy[ ] and Ford[ ]. Next, list the winner of each pair, giving the number of seconds the winner won by. At the end, declare which team won based on which team had the most wins.
Input chevy[0] to chevy[7]
Input ford[0] to ford[7]
Output
Explanation / Answer
Hi,
Please find the converted code :
using System;
public class Test
{
public static void Main()
{
int[] chevy=new int[8];
int[] ford=new int[8];
int chevyCount=0,fordCount=0;
Console.WriteLine("Enter 8 Drag time for Chevy : ");
for (int i = 0; i < chevy.Length; i++)
{
chevy[i]=Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Enter 8 Drag time for Ford : ");
for (int i = 0; i < chevy.Length; i++)
{
chevy[i]=Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("And the winners are : ");
for (int i = 0; i <=7; i++)
{
if(chevy[i] > ford[i])
{
Console.WriteLine("Chevy won by "+ (chevy[i] - ford[i]));
chevyCount ++;
}
else if(chevy[i] < ford[i])
{
Console.WriteLine("Ford won by "+ (ford[i]- chevy[i] ));
fordCount ++;
}
else
{
Console.WriteLine("It was a tie");
}
}
Console.WriteLine("And the winning team is : ");
if(chevyCount > fordCount)
{
Console.WriteLine("Chevy with "+chevyCount +" points");
}
else if(fordCount < chevyCount)
{
Console.WriteLine("Ford with "+fordCount +" points");
}
else
{
Console.WriteLine("It was a tie");
}
}
}