Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Console Application

Console Application

Scheduled Pinned Locked Moved C#
csharphelp
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mil_an
    wrote on last edited by
    #1

    Hi, I have little experience writing code, so your help is much needed, and will be really appreciated....please help!! I need to build a CONSOLE application, written in C#, It should cycle thru the states as shown: Stop -> Prepare to Go, Prepare to Go -> Go, Go -> Prepare to Stop. Thanks...in advance __________________________________________ This is what I have come up with till now, but it seems wrong: using System; namespace traffic_light { /// /// Summary description for Class1. /// enum State { prepare_to_go, go, prepare_to_stop, stop, } class Class1 { private State _state; public Class1() { _state = State.prepare_to_go; Console.WriteLine ( _state ); _state = State.go; Console.WriteLine ( _state ); _state = State.prepare_to_stop; Console.WriteLine ( _state ); _state = State.stop; Console.WriteLine ( _state ); } } }

    J M 2 Replies Last reply
    0
    • M mil_an

      Hi, I have little experience writing code, so your help is much needed, and will be really appreciated....please help!! I need to build a CONSOLE application, written in C#, It should cycle thru the states as shown: Stop -> Prepare to Go, Prepare to Go -> Go, Go -> Prepare to Stop. Thanks...in advance __________________________________________ This is what I have come up with till now, but it seems wrong: using System; namespace traffic_light { /// /// Summary description for Class1. /// enum State { prepare_to_go, go, prepare_to_stop, stop, } class Class1 { private State _state; public Class1() { _state = State.prepare_to_go; Console.WriteLine ( _state ); _state = State.go; Console.WriteLine ( _state ); _state = State.prepare_to_stop; Console.WriteLine ( _state ); _state = State.stop; Console.WriteLine ( _state ); } } }

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      You're not too far away. Since you're obviously trying to learn something new, I'll provide leading questions rather than actual answers. 1) How many times is it supposed to cycle through these states? 2) How would you write code to do something that many times? 3) Does the code you have successfully perform one complete state change cycle? 4) (Less important) Would a separate class method (not the constructor) be a better place to do this work? John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      M 1 Reply Last reply
      0
      • M mil_an

        Hi, I have little experience writing code, so your help is much needed, and will be really appreciated....please help!! I need to build a CONSOLE application, written in C#, It should cycle thru the states as shown: Stop -> Prepare to Go, Prepare to Go -> Go, Go -> Prepare to Stop. Thanks...in advance __________________________________________ This is what I have come up with till now, but it seems wrong: using System; namespace traffic_light { /// /// Summary description for Class1. /// enum State { prepare_to_go, go, prepare_to_stop, stop, } class Class1 { private State _state; public Class1() { _state = State.prepare_to_go; Console.WriteLine ( _state ); _state = State.go; Console.WriteLine ( _state ); _state = State.prepare_to_stop; Console.WriteLine ( _state ); _state = State.stop; Console.WriteLine ( _state ); } } }

        M Offline
        M Offline
        mil_an
        wrote on last edited by
        #3

        The error I receive when I run the above piece of code is: 'ConsoleApplication1.exe' does not have an entry point defined. I don't know hopw to rectify the above problem, please help!! Thanks...

        C O 2 Replies Last reply
        0
        • M mil_an

          The error I receive when I run the above piece of code is: 'ConsoleApplication1.exe' does not have an entry point defined. I don't know hopw to rectify the above problem, please help!! Thanks...

          C Offline
          C Offline
          CWIZO
          wrote on last edited by
          #4

          You must have a Main method in your class: public static void Main () { // put your code here! } Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

          1 Reply Last reply
          0
          • J John Fisher

            You're not too far away. Since you're obviously trying to learn something new, I'll provide leading questions rather than actual answers. 1) How many times is it supposed to cycle through these states? 2) How would you write code to do something that many times? 3) Does the code you have successfully perform one complete state change cycle? 4) (Less important) Would a separate class method (not the constructor) be a better place to do this work? John
            "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

            M Offline
            M Offline
            mil_an
            wrote on last edited by
            #5

            Hi, Thanks for your assistance, John. It is meant to cycle through these states continuosly...lets say about 5 times. Its meant to pause at each state for a certain amount of time, say about 5 seconds on each state. Could you give me some pointers in sorting this out. Also the code posted above does not run, because during compilation I get this error: "ConsoleApplication1.exe" does not have an entry point defined. Thanks alot for your help...much appreciated!!

            N 1 Reply Last reply
            0
            • M mil_an

              Hi, Thanks for your assistance, John. It is meant to cycle through these states continuosly...lets say about 5 times. Its meant to pause at each state for a certain amount of time, say about 5 seconds on each state. Could you give me some pointers in sorting this out. Also the code posted above does not run, because during compilation I get this error: "ConsoleApplication1.exe" does not have an entry point defined. Thanks alot for your help...much appreciated!!

              N Offline
              N Offline
              Nick Parker
              wrote on last edited by
              #6

              Here is one simple way to loop 5 times and pause for 5 seconds each time. Hope this gets you going in the right direction.

              for(int i = 0; i < 5;i++)
              {
              // Sleep for 5 seconds.
              System.Thread.Sleep(5000);
              }

              - Nick Parker
                My Blog

              1 Reply Last reply
              0
              • M mil_an

                The error I receive when I run the above piece of code is: 'ConsoleApplication1.exe' does not have an entry point defined. I don't know hopw to rectify the above problem, please help!! Thanks...

                O Offline
                O Offline
                oOomen
                wrote on last edited by
                #7

                hi, here is everything u need ;-) i hope it helps u! using System; using System.Threading; // needs to use Thread class namespace ConsoleApplication1 { // the class with main function class Class { /// /// The main entry point for the application. /// static void Main() { // create new Traffic_light object Traffic_light t_l = new Traffic_light(); // loop 10 times for(int i = 0; i < 10; i ++) { t_l.ShowState(); // show current state Thread.Sleep(5000); // wait 5 seconds } // show exit msg. Console.WriteLine("press enter to exit"); Console.ReadLine(); } } // the class u need class Traffic_light { // array with ur states private string[] Array; // index of currrent state private int State; // Constructor to set up default values public Traffic_light() { State = 0; Array = new string[] { "prepare to go", "go", "prepare to stop", "stop" }; } // function u need to show current state // new call - new state public void ShowState() { State %= Array.Length; // same as: State = State % Array.Length; Console.WriteLine(Array[State ++]); // same as: Console.WriteLine(Array[State]); State = State + 1; } } } output u see: ==================== prepare to go go prepare to stop stop prepare to go go prepare to stop stop prepare to go go press enter to exit ==================== best regards !:)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups