Програма не отображается в консоли Требует Main, а я не знаю куда його вставить. C#
Программа на с# должна выводить на консоль имя машины и ее силу , но ничего не отображается. Помогите пофиксить код , пожалуйста вот мой код
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab_1_3
{
class Car
{
private string name;
private double power;
public void setname(string n)
{
name = n;
}
public void setpower(double p)
{
power = p;
}
public void GetCarInfo()
{
Console.WriteLine(name + " " + power);
}
public bool motor()
{
if (power == 2.0f & power > 2.0f)
{
return true;
}
else return false;
}
}
class Program
{
static void Car(string[] args)
{
Car[] car_array = new Car[30];
for (int i = 0; i < car_array.Length; i++)
{
car_array[i] = new Car();
}
string name;
for (int i = 0; i < car_array.Length; i++)
{
name = "Car_" + i;
car_array[i].setname(name);
}
double power;
for (int i = 0; i < car_array.Length; i++)
{
Console.Write("Enter the power of a motor: ");
power = Convert.ToDouble(Console.ReadLine());
car_array[i].setpower(power);
}
Console.WriteLine();
Console.WriteLine("Here is the list of the cars:");
for (int i = 0; i < car_array.Length; i++)
{
car_array[i].GetCarInfo();
}
double powerful = 0.0;
for (int i = 0; i < car_array.Length; i++)
{
if (car_array[i].motor() == true & car_array[i].motor() == true) powerful++;
}
Console.WriteLine("The number of powerful cars is" + powerful);
Console.ReadKey();
}
}
}```
Ответы (1 шт):
Автор решения: grouptout
→ Ссылка
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab_1_3
{
class Car
{
private string name;
private double power;
public void setname(string n)
{
name = n;
}
public void setpower(double p)
{
power = p;
}
public void GetCarInfo()
{
Console.WriteLine(name + " " + power);
}
public bool motor()
{
if (power == 2.0f & power > 2.0f)
{
return true;
}
else return false;
}
}
class Program
{
static void Main(string[] args)
{
Car[] car_array = new Car[30];
for (int i = 0; i < car_array.Length; i++)
{
car_array[i] = new Car();
}
string name;
for (int i = 0; i < car_array.Length; i++)
{
name = "Car_" + i;
car_array[i].setname(name);
}
double power;
for (int i = 0; i < car_array.Length; i++)
{
Console.Write("Enter the power of a motor: ");
power = Convert.ToDouble(Console.ReadLine());
car_array[i].setpower(power);
}
Console.WriteLine();
Console.WriteLine("Here is the list of the cars:");
for (int i = 0; i < car_array.Length; i++)
{
car_array[i].GetCarInfo();
}
double powerful = 0.0;
for (int i = 0; i < car_array.Length; i++)
{
if (car_array[i].motor() == true & car_array[i].motor() == true) powerful++;
}
Console.WriteLine("The number of powerful cars is" + powerful);
Console.ReadKey();
}
}
}