C# program runs but then terminates? -


i'm using visual studios 2012 , i'm creating program prompts user enter number of wheels car has, color of car, mileage etc.. , display 'the starting point of car, mileage, , color of car once user inputs values. but, once start program , enter number of wheels, program terminates , doesn't go next step.

public class car {          private int numbofwheels;         private int mileage;         private string color;         private double point;         private double newpoint;         private string owner;          static void main(string[] args)         {                console.writeline("****************************************");             console.writeline("*           welcome car manager     *");             console.writeline();             console.writeline("*             by: mohamed shire        *");             console.writeline("*                                      *");             console.writeline("*                                      *");             console.writeline("* **************************************");             console.write("enter # of wheels of car: ");             console.readkey();         }          public car()         {             mileage = 0;             numbofwheels = 4;             point = 1000000;         }          public car(int mile)         {             mileage = mile;         }         public car(int n, string c)        {            mileage = 0;            numbofwheels = n;            color = c;            point = 1000000;        }      public void setpoint( int p)     {         point = p;     }       public double getpoint()     {         return point;     }     public void setmileage(int m)     {         mileage = m;      }      public int getmileage()     {         return mileage;     }      public void setwheels(int w)     {         numbofwheels = w;      }      public int getwheels()     {          return numbofwheels;     }      public void setcolor(string c)     {         color = c;      }      public string getcolor()     {         return color;      }     public void setowner(string o)     {         owner = o;     }     public string getowner()     {         return owner;      }      public void calpoint()     {         newpoint = point - mileage * 0.5;      }     public double getnpoint()     {         return newpoint;     }        } } 

'

this code program ever executes

        console.writeline("****************************************");         console.writeline("*           welcome car manager     *");         console.writeline();         console.writeline("*             by: mohamed shire        *");         console.writeline("*                                      *");         console.writeline("*                                      *");         console.writeline("* **************************************");         console.write("enter # of wheels of car: ");         console.readkey(); 

you define other classes , methods, never create instance of class , never call class methods.

you want figure out key pressed

var key = console.readkey(); 

and key.

you want convert key integer because methods of car need integer. there 3 common ways that:

  • int.parse()
  • convert.toint32()
  • int.tryparse()

of those, int.tryparse() gives best control because can check whether input converted integer without catching exceptions.

you need repeat pattern of console.write() , console.readkey() additional input need, create instance of car pass input on to.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -