Нужно выявить сумму всех авто (price), ответ всегда выводится 50.
Как правильно передать параметры по значению?
int sum = 0;
for (int j = 0; j < k; j++)
{
smallcar[j].all_price(ref j,ref sum);
}
sum.ToString();
Console.Write(sum);
public void all_price(ref int i,ref int summ)
{
summ = 0;
summ = summ + Convert.ToInt32(price[i]);
}
Console.Write("Введите количество легковых авто: ");
int k = Convert.ToInt32(Console.ReadLine());
Passengercar[] smallcar = new Passengercar[k];
int i = 0;
while (i < k)
{
smallcar[i] = new Passengercar();
Console.WriteLine("\nВведите характеристики " + i + "-го легкового авто");
Console.Write(" марка: ");
smallcar[i].marka = Console.ReadLine();
Console.Write(" модель: ");
smallcar[i].model = Console.ReadLine();
Console.Write(" страна-изготовитель: ");
smallcar[i].countryrelease = Console.ReadLine();
Console.Write(" цвет: ");
smallcar[i].color = Console.ReadLine();
Console.Write(" цена: ");
smallcar[i].price = Console.ReadLine();
Console.Write(" радиус колёс: ");
smallcar[i].rwheels = Console.ReadLine();
i++;
}
class Auto
{
public string marka;
public string model;
public string countryrelease;
public string color;
public string price;
}
class Passengercar : Auto
{
public string rwheels;
public void show_pass_car(int k)
{
Console.WriteLine("Авто " + k.ToString() + ": " + marka + " " + model + " " +
countryrelease + " " + color + " " + price + " " + rwheels);
}