C
C#8mo ago
Muhammad

❔ ✅ It's not writing to the console that car1 is driving

Car car1 = new Car("ford", "mustang", 2022, "red");
Car car2 = new Car("idk", "idk", 2001, "idk");
Console.WriteLine();
Console.ReadLine();

car1.Drive();


class Car
{
string make;
string model;
int year;
string colour;
public static int numberOfCars;


public Car(string make, string model, int year, string colour)
{
this.make = make;
this.model = model;
this.year = year;
this.colour = colour;
numberOfCars++;
}

public void Test()
{
Console.WriteLine(numberOfCars);
}
public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
Console.ReadLine();
}

}
Car car1 = new Car("ford", "mustang", 2022, "red");
Car car2 = new Car("idk", "idk", 2001, "idk");
Console.WriteLine();
Console.ReadLine();

car1.Drive();


class Car
{
string make;
string model;
int year;
string colour;
public static int numberOfCars;


public Car(string make, string model, int year, string colour)
{
this.make = make;
this.model = model;
this.year = year;
this.colour = colour;
numberOfCars++;
}

public void Test()
{
Console.WriteLine(numberOfCars);
}
public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
Console.ReadLine();
}

}
3 Replies
Pobiega
Pobiega8mo ago
remove the Console.ReadLine() in your top level code
Muhammad
Muhammad8mo ago
shoot where did that come from thank you :)) !close
Accord
Accord8mo ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.