Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Rewrite the following code and create a function to display the planets and thei

ID: 3592815 • Letter: R

Question

Rewrite the following code and create a function to display the planets and their diameters. Instead of the code in main, create a function to do this. Pass both arrays to the function.

static void Main(string[] args)

{

string[] planet = new string[]{"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};

double[] diameter = new double[] { 4879, 12104, 12756, 6792, 142984, 120536, 51118, 49528 };

Console.WriteLine("Each planet and its diameter are shown below:");

for(int i=0;i<8;i++)

{

Console.Write(" Planet: "+planet[i]);

Console.Write(" Diameter: "+diameter[i]);

}

Console.ReadLine();

}

}

need a conclusion statement on this as well. thanks.

Explanation / Answer

Ans) I have created the function for them to arrays and passing the values through that functions. Please find the below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace planet
{
class Program
{
static void Main(string[] args)
{
string[] planet = new string[] { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };
double[] diameter = new double[] { 4879, 12104, 12756, 6792, 142984, 120536, 51118, 49528 };
plants(planet, diameter);
  
}

private static void plants(string[] planet, double[] diameter)
{
Console.WriteLine("Each planet and its diameter are shown below:");
for (int i = 0; i < 8; i++)
{
Console.Write(" Planet: " + planet[i]);
Console.Write(" Diameter: " + diameter[i]);
}
Console.ReadLine();
}



}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote