Below is a program sample from the book "Teach Yourself the C# Language in
21 Days."
I've compiled the program and receieved no errors - but it does not do what
is expected.
I've compared it to the smae sample on the CD - and it appears to be exactly
the same - yet it does not do what it should.
When executed it should ask you to select a color - once you do the
appropriate message will display on the console.
Any help is appreciated.
Thank You in Advance.
Kim
//color.cs - using enumeration
// Note: entering a non-numeric number when running this program will cause
an exception to be thrown.
//.
//.................................................. ........................
.....................
using System;
class Colors
{
enum Color
{
red,
white,
blue
}
public static void Main()
{
string buffer;
Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):
");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor )
{
case Color.red:
System.Console.WriteLine("\nSwitched to Red...");
break;
case Color.white:
System.Console.WriteLine("\nSwitched to White...");
break;
case Color.blue:
System.Console.WriteLine("\nSwitched to Blue...");
break;
default:
System.Console.WriteLine("\nSwitched to Default...");
break;
}
System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int) myColor);
}
} 9 1629
Hi,
What it does?
I created a new console project, paste your code and does correctly display
the string, the only thing I changed was that I change the signature of
Main:
[STAThread]
static void Main(string[] args)
and added a Console.ReadLine() after the printout
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
using System;
namespace ConsoleApplication6
{
class Class1
{
enum Color
{
red,
white,
blue
}
[STAThread]
static void Main(string[] args)
{
string buffer;
Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 =
Blue):");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor )
{
case Color.red:
System.Console.WriteLine("\nSwitched to Red...");
break;
case Color.white:
System.Console.WriteLine("\nSwitched to White...");
break;
case Color.blue:
System.Console.WriteLine("\nSwitched to Blue...");
break;
default:
System.Console.WriteLine("\nSwitched to Default...");
break;
}
System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int) myColor);
System.Console.ReadLine();
}
}
}
"Kim" <ki*@xxx.com> wrote in message
news:Sz**************@bignews7.bellsouth.net... Below is a program sample from the book "Teach Yourself the C# Language in 21 Days." I've compiled the program and receieved no errors - but it does not do what is expected. I've compared it to the smae sample on the CD - and it appears to be exactly the same - yet it does not do what it should. When executed it should ask you to select a color - once you do the appropriate message will display on the console.
Any help is appreciated. Thank You in Advance. Kim
//color.cs - using enumeration // Note: entering a non-numeric number when running this program will cause an exception to be thrown. //. //.................................................. ........................ ....................
using System;
class Colors { enum Color { red, white, blue }
public static void Main() { string buffer; Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 = Blue): ");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor ) { case Color.red: System.Console.WriteLine("\nSwitched to Red..."); break; case Color.white: System.Console.WriteLine("\nSwitched to White..."); break; case Color.blue: System.Console.WriteLine("\nSwitched to Blue..."); break; default: System.Console.WriteLine("\nSwitched to Default..."); break; } System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int) myColor); } }
Kim wrote: Below is a program sample from the book "Teach Yourself the C# Language in 21 Days." I've compiled the program and receieved no errors - but it does not do what is expected. I've compared it to the smae sample on the CD - and it appears to be exactly the same - yet it does not do what it should. When executed it should ask you to select a color - once you do the appropriate message will display on the console.
What does it do when you execute the program? I copied and pasted your
code directly into a console application. When running the behavior is
as follows:
- I am prompted with the message:
"Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):"
- I enter 1
- The following text is output on the console:
Switched to White...
Color is white (1)
- The program ends
Based on the code that appears to be the correct behavior. What are you
expecting it to do?
--
Tom Porterfield
Try running it with a ctrl-f5,
Then it'll pause at the console after execution.
"Kim" <ki*@xxx.com> wrote in message
news:Sz**************@bignews7.bellsouth.net... Below is a program sample from the book "Teach Yourself the C# Language in 21 Days." I've compiled the program and receieved no errors - but it does not do what is expected. I've compared it to the smae sample on the CD - and it appears to be exactly the same - yet it does not do what it should. When executed it should ask you to select a color - once you do the appropriate message will display on the console.
Any help is appreciated. Thank You in Advance. Kim
//color.cs - using enumeration // Note: entering a non-numeric number when running this program will cause an exception to be thrown. //. //.................................................. ........................ ....................
using System;
class Colors { enum Color { red, white, blue }
public static void Main() { string buffer; Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 = Blue): ");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor ) { case Color.red: System.Console.WriteLine("\nSwitched to Red..."); break; case Color.white: System.Console.WriteLine("\nSwitched to White..."); break; case Color.blue: System.Console.WriteLine("\nSwitched to Blue..."); break; default: System.Console.WriteLine("\nSwitched to Default..."); break; } System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int) myColor); } }
thanks - I am running this at the dos prompt
"Pratush Bajpai" <pr************@persistent.co.in> wrote in message
news:uG**************@TK2MSFTNGP14.phx.gbl... Try running it with a ctrl-f5, Then it'll pause at the console after execution.
"Kim" <ki*@xxx.com> wrote in message news:Sz**************@bignews7.bellsouth.net... Below is a program sample from the book "Teach Yourself the C# Language
in 21 Days." I've compiled the program and receieved no errors - but it does not do what is expected. I've compared it to the smae sample on the CD - and it appears to be exactly the same - yet it does not do what it should. When executed it should ask you to select a color - once you do the appropriate message will display on the console.
Any help is appreciated. Thank You in Advance. Kim
//color.cs - using enumeration // Note: entering a non-numeric number when running this program will cause an exception to be thrown. //.
//.................................................. ........................ ....................
using System;
class Colors { enum Color { red, white, blue }
public static void Main() { string buffer; Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 =
Blue): ");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor ) { case Color.red: System.Console.WriteLine("\nSwitched to Red..."); break; case Color.white: System.Console.WriteLine("\nSwitched to White..."); break; case Color.blue: System.Console.WriteLine("\nSwitched to Blue..."); break; default: System.Console.WriteLine("\nSwitched to Default..."); break; } System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int)
myColor); } }
Hi Tom,
thank you for replying.
When I run it - I get no response.
I am running it from the dos prompt
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:#R**************@TK2MSFTNGP14.phx.gbl... Kim wrote: Below is a program sample from the book "Teach Yourself the C# Language
in 21 Days." I've compiled the program and receieved no errors - but it does not do
what is expected. I've compared it to the smae sample on the CD - and it appears to be
exactly the same - yet it does not do what it should. When executed it should ask you to select a color - once you do the appropriate message will display on the console.
What does it do when you execute the program? I copied and pasted your code directly into a console application. When running the behavior is as follows:
- I am prompted with the message: "Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):" - I enter 1 - The following text is output on the console: Switched to White...
Color is white (1) - The program ends
Based on the code that appears to be the correct behavior. What are you expecting it to do? -- Tom Porterfield
Hi,
I commented out all of your changes and it works.
question is - what is wrong with the one i posted originally.
it makes no sense.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:#t**************@TK2MSFTNGP09.phx.gbl... Hi,
What it does?
I created a new console project, paste your code and does correctly
display the string, the only thing I changed was that I change the signature of Main: [STAThread] static void Main(string[] args)
and added a Console.ReadLine() after the printout
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation using System;
namespace ConsoleApplication6 { class Class1 { enum Color { red, white, blue } [STAThread] static void Main(string[] args) { string buffer; Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor ) { case Color.red: System.Console.WriteLine("\nSwitched to Red..."); break; case Color.white: System.Console.WriteLine("\nSwitched to White..."); break; case Color.blue: System.Console.WriteLine("\nSwitched to Blue..."); break; default: System.Console.WriteLine("\nSwitched to Default..."); break; } System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int)
myColor); System.Console.ReadLine(); }
} }
"Kim" <ki*@xxx.com> wrote in message news:Sz**************@bignews7.bellsouth.net... Below is a program sample from the book "Teach Yourself the C# Language
in 21 Days." I've compiled the program and receieved no errors - but it does not do what is expected. I've compared it to the smae sample on the CD - and it appears to be exactly the same - yet it does not do what it should. When executed it should ask you to select a color - once you do the appropriate message will display on the console.
Any help is appreciated. Thank You in Advance. Kim
//color.cs - using enumeration // Note: entering a non-numeric number when running this program will cause an exception to be thrown. //.
//.................................................. ........................ ....................
using System;
class Colors { enum Color { red, white, blue }
public static void Main() { string buffer; Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 =
Blue): ");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor ) { case Color.red: System.Console.WriteLine("\nSwitched to Red..."); break; case Color.white: System.Console.WriteLine("\nSwitched to White..."); break; case Color.blue: System.Console.WriteLine("\nSwitched to Blue..."); break; default: System.Console.WriteLine("\nSwitched to Default..."); break; } System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int)
myColor); } }
"Kim" <ki*@xxx.com> wrote in message news:Fg***************@bignews7.bellsouth.net... Hi Tom, thank you for replying. When I run it - I get no response. I am running it from the dos prompt
I copied your code int test.cs
compiled it from a DOS window (csc *.cs)
and ran it.
Here is the output when run 4 times
-----------------------------------------------------
C:\Code\dotnet\test>test
Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):0
Switched to Red...
Color is red (0)
C:\Code\dotnet\test>test
Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):1
Switched to White...
Color is white (1)
C:\Code\dotnet\test>test
Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):2
Switched to Blue...
Color is blue (2)
C:\Code\dotnet\test>test
Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):3
Switched to Default...
Color is 3 (3)
C:\Code\dotnet\test>
----------------------------------------------------------
Silly question:
Are you pressing ENTER after selecting a value?
Assuming that you are:
Try putting some Console.WriteLine statements in there to see if you can spot what is happening.
It should work
Bill
hi
The only thing I changed was the signature of the Main method:
[STAThread]
static void Main(string[] args)
and included a ReadLine at the end.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Kim" <ki*@xxx.com> wrote in message
news:hl***************@bignews7.bellsouth.net... Hi, I commented out all of your changes and it works. question is - what is wrong with the one i posted originally. it makes no sense.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:#t**************@TK2MSFTNGP09.phx.gbl... Hi,
What it does?
I created a new console project, paste your code and does correctly display the string, the only thing I changed was that I change the signature of Main: [STAThread] static void Main(string[] args)
and added a Console.ReadLine() after the printout
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation using System;
namespace ConsoleApplication6 { class Class1 { enum Color { red, white, blue } [STAThread] static void Main(string[] args) { string buffer; Color myColor;
Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):");
buffer = Console.ReadLine();
myColor = (Color) Convert.ToInt32(buffer);
switch( myColor ) { case Color.red: System.Console.WriteLine("\nSwitched to Red..."); break; case Color.white: System.Console.WriteLine("\nSwitched to White..."); break; case Color.blue: System.Console.WriteLine("\nSwitched to Blue..."); break; default: System.Console.WriteLine("\nSwitched to Default..."); break; } System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int) myColor); System.Console.ReadLine(); }
} }
"Kim" <ki*@xxx.com> wrote in message news:Sz**************@bignews7.bellsouth.net... > Below is a program sample from the book "Teach Yourself the C# Language in > 21 Days." > I've compiled the program and receieved no errors - but it does not do > what > is expected. > I've compared it to the smae sample on the CD - and it appears to be > exactly > the same - yet it does not do what it should. > When executed it should ask you to select a color - once you do the > appropriate message will display on the console. > > Any help is appreciated. > Thank You in Advance. > Kim > > > //color.cs - using enumeration > // Note: entering a non-numeric number when running this program will > cause > an exception to be thrown. > //. > //.................................................. ........................ > .................... > > using System; > > class Colors > { > enum Color > { > red, > white, > blue > } > > public static void Main() > { > string buffer; > Color myColor; > > Console.Write("Enter a value for a color: 0 = Red, 1 = White, 2 = Blue): > "); > > buffer = Console.ReadLine(); > > myColor = (Color) Convert.ToInt32(buffer); > > switch( myColor ) > { > case Color.red: > System.Console.WriteLine("\nSwitched to Red..."); > break; > case Color.white: > System.Console.WriteLine("\nSwitched to White..."); > break; > case Color.blue: > System.Console.WriteLine("\nSwitched to Blue..."); > break; > default: > System.Console.WriteLine("\nSwitched to Default..."); > break; > } > System.Console.WriteLine("\nColor is {0} ({1})", myColor, (int) myColor); > } > } > > > >
It is the strangest thing.
Yes I am hitting the enter key.
The sample off the CD works as it should.
I added Console.WriteLine("I am here");
as the first line of the program
after the Main() and still I get no response.
bizarro!
"Bill Butler" <qw****@asdf.com> wrote in message
news:Prs5f.6321$fC3.4809@trndny01... "Kim" <ki*@xxx.com> wrote in message
news:Fg***************@bignews7.bellsouth.net... Hi Tom, thank you for replying. When I run it - I get no response. I am running it from the dos prompt
I copied your code int test.cs compiled it from a DOS window (csc *.cs) and ran it.
Here is the output when run 4 times ----------------------------------------------------- C:\Code\dotnet\test>test Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):0
Switched to Red...
Color is red (0)
C:\Code\dotnet\test>test Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):1
Switched to White...
Color is white (1)
C:\Code\dotnet\test>test Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):2
Switched to Blue...
Color is blue (2)
C:\Code\dotnet\test>test Enter a value for a color: 0 = Red, 1 = White, 2 = Blue):3
Switched to Default...
Color is 3 (3)
C:\Code\dotnet\test>
---------------------------------------------------------- Silly question: Are you pressing ENTER after selecting a value?
Assuming that you are: Try putting some Console.WriteLine statements in there to see if you can
spot what is happening.
It should work
Bill This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kerry Neilson |
last post by:
For the past couple of months, Idle won't start when I invoke it. I
am at a complete loss for why this is. When this happens, they python
command line still starts, and python works fine...
|
by: Jim |
last post by:
Hey guys
I DESPERATLY need some help with this small javascript i have on this
website. All that it's supposed to do is change the button image once
it's pressed but alas... I copy-pasted the code...
|
by: DFS |
last post by:
I've been working around this for years (I believe), so I figured someone
here might know:
Why won't a crosstab query accept a value from a form reference?
TRANSFORM...
|
by: simon |
last post by:
I have simple html(aspx) page, but vertical height won't work.
Even if i had set the height of a table=100%, the table is not 100% height.
I spend a lot of time(my real page is more...
|
by: musosdev |
last post by:
Hi guys
Okay, I've setup my projects to open and compile fine in VS2005 using FPSE
and remote web, but it's *really* slow. So I thought I'd have a go at doing
it the normal way, by loading from...
|
by: John Ortt |
last post by:
Hi everyone.
I have a database which I have developed in Access 2000 which is working
nicely.
The problem is that my customer only has Access 97. I tried to convert the
database but the main...
|
by: Eran.Yasso |
last post by:
Hi,
I have project that automate excel(using Excel COM) which works fine
in my home.
I took the project from my home to work and tried to build the project
but it won't built.
I get error "The...
|
by: scitrenbaum |
last post by:
Here is the dilemma. I have a website where everything works perfectly in all browsers except for Safari.
When you are in Safari and you go to this page...
...
|
by: tpgames |
last post by:
Two days ago, MS office Word would type JP fonts, I thought. I didn't think I was using Works. Now, it won't type in JP. Jasc Paint shop pro 8, should type JP fonts because I am using XP, according...
|
by: z55177 |
last post by:
My domain: http://www.esthevision.cz/
This is the cause of my problem.
The template is supposed to look somewhat like this: PINK STRIPE
http://themebot.com/website-templates/ht...
I created an...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |