hello everyone i have wrote a code but i have problem compiling it ( making it run )

it's running but there are no any text's that i'm typing in Writeline

here's the code!

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

namespace ConsoleApplication5 {
    class Program {
        static void Main(string[] args)
        {
            cars e1 = new cars();
            books e2 = new books();

            //cars parameters

           e1.mark = "BMW";
           e1.model = "M3";
           e1.color = "Silver";
           e1.price = 13000;



            //book parameters
           e2.author = "Fyodor Dostoyevsky";
           e2.genre = "morality";
           e2.name = "The Brothers Karamazov";
           e2.price = 25;

           Console.WriteLine(e1);
           Console.ReadKey();


        }
    }
}


class cars {

    public string mark;
    public string model;
    public string color;
    public double price;
    public void WriteInfo()
    {
        Console.WriteLine("cars: mark: {0} model: {1}. color: {2}. price: {3}", mark, model, color, price);
    }



}

class books {
    public string author;
    public string genre;
    public string name;
    public double price;

    public void WriteInfo()
    {
        Console.WriteLine("books: author: {0} genre: {1}. name: {2}. price: {3}", author, genre, name, price);
    }
}

Recommended Answers

All 4 Replies

You arent calling the method from your class to the static vodi main()

can u write the correct source code for me ? thx

class cars
{
    public  string mark;
    public  string model;
    public   string color;
    public  double price;
    public cars(string markee, string modelee, string coloree,double pricee) 
    {
        mark = markee;
        model = modelee;
        color = coloree;
        price = pricee;
    }
    public  void WriteInfo()
    {
        Console.WriteLine("cars: mark: {0} model: {1}. color: {2}. price: {3}", mark, model, color, price);
    }
}

class Program
    {
        static void Main(string[] args)
        {
            cars e1 = new cars("bmq","","",0.2);
            books e2 = new books();



            e1.WriteInfo();

            //book parameters
            e2.author = "Fyodor Dostoyevsky";
            e2.genre = "morality";
            e2.name = "The Brothers Karamazov";
            e2.price = 25;
            Console.WriteLine(e1);
            Console.ReadKey();
        }
    }

use a constructor for this SO that you can built your object, learn constructors, i ve put some silly values inside but you ll figure it out, do the rest on your own

try this then:
`

 class Program
    {
        static void Main(string[] args)
        {
            cars.color = "blue";
            cars.price = 0.2;
            cars.model = "volvo";
            cars.mark = "volvo";



            cars.WriteInfo();

            //book parameters

            Console.ReadKey();
        }
    }
}
class cars
{
    public  static string mark;
    public  static string model;
    public   static string color;
    public  static double price;

    public static  void WriteInfo()
    {
        Console.WriteLine("cars: mark: {0} model: {1}. color: {2}. price: {3}", mark, model, color, price);
    }
}

`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.