11 Replies - 790 Views - Last Post: 18 September 2012 - 01:12 AM Rate Topic: -----

#1 5mattmatt1  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 36
  • Joined: 21-July 12

string error in c#

Posted 15 September 2012 - 04:34 PM

string name;
            string charclass;
            string teacher;
            Console.WriteLine("What is your name?");
            name = Console.ReadLine();
            Console.WriteLine("Hello brave warrior " + name + ".");
            Console.ReadLine();
            Console.WriteLine("Which of the following classes do you wish to become Warrior,Mage, or Rogue?");
            charclass = Console.ReadLine();
            switch (charclass)
            {
                case "warrior":
                    Console.WriteLine("Your teacher is Balkan");
                    teacher = Balkan;
                    break;
                case "mage":
                    Console.WriteLine("Your teacher is Artrix");
                    teacher = Artrix;
                    break;
            }
            Console.ReadLine();
            Console.WriteLine("Welcome to " + teacher + "'s class");


i wrote this code and i want it to say the teacher name(last line) but it acts as though i never defined the name(right before the breaks) what do i need to change

Is This A Good Question/Topic? 0
  • +

Replies To: string error in c#

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,246
  • Joined: 28-March 11

Re: string error in c#

Posted 15 September 2012 - 04:45 PM

C#? You posted in C/C++! I will move this for you...
Was This Post Helpful? 0
  • +
  • -

#3 5mattmatt1  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 36
  • Joined: 21-July 12

Re: string error in c#

Posted 15 September 2012 - 04:50 PM

thanks
Was This Post Helpful? 0
  • +
  • -

#4 5mattmatt1  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 36
  • Joined: 21-July 12

Re: string error in c#

Posted 15 September 2012 - 05:02 PM

any ideas
Was This Post Helpful? 0
  • +
  • -

#5 5mattmatt1  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 36
  • Joined: 21-July 12

Re: string error in c#

Posted 15 September 2012 - 05:47 PM

anyone know how to fix this
Was This Post Helpful? -1
  • +
  • -

#6 5mattmatt1  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 36
  • Joined: 21-July 12

Re: string error in c#

Posted 15 September 2012 - 06:24 PM

            string charclass;
            string teacher;
            Console.WriteLine("What is your name?");
            name = Console.ReadLine();
            Console.WriteLine("Hello brave warrior " + name + ".");
            Console.ReadLine();
            Console.WriteLine("Which of the following classes do you wish to become Warrior,Mage, or Rogue?");
            charclass = Console.ReadLine();
            switch (charclass)
            {
                case "warrior":
                    Console.WriteLine("Your teacher is Balkan");
                    teacher = Balkan;
                    break;
                case "mage":
                    Console.WriteLine("Your teacher is Artrix");
                    teacher = Artrix;
                    break;
            }
            Console.ReadLine();
            Console.WriteLine("Welcome to " + teacher + "'s class");



it doesn't put in the teachers name in the last line
Was This Post Helpful? -1
  • +
  • -

#7 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1251
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: string error in c#

Posted 15 September 2012 - 06:28 PM

The reason being that the teacher variable must be remaining empty.

As such, put a breakpoint in the switch case and check if flow is entering the case statements you wrote. Chances are they're not.
Was This Post Helpful? 1
  • +
  • -

#8 5mattmatt1  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 36
  • Joined: 21-July 12

Re: string error in c#

Posted 15 September 2012 - 06:31 PM

i did put in break;
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,366
  • Joined: 02-June 10

Re: string error in c#

Posted 15 September 2012 - 07:12 PM

Not a break; command.

A breakpoint. Please do the debugging tutors in FAQ 2 and it will become clear.

5mattmatt1: What this shows us is that you aren't familiar with breakpoints and how to debug your own code. Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


See FAQ # 2. (Click the SHOW button below)



TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated July 2012
Spoiler



This post has been edited by tlhIn`toq: 15 September 2012 - 07:12 PM

Was This Post Helpful? 1
  • +
  • -

#10 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: string error in c#

Posted 16 September 2012 - 03:48 AM

Merged duplicate topics. Do NOT create a new topic when you already have one open on the same subject.

And don't bump your topic after only a few minutes; this ISN'T a ******* chat room.
Was This Post Helpful? 0
  • +
  • -

#11 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 996
  • View blog
  • Posts: 2,393
  • Joined: 04-October 09

Re: string error in c#

Posted 16 September 2012 - 09:34 AM

Not only doesn't it put the name in, the code you posted won't even compile. Please post the actual code you are using.
Was This Post Helpful? 0
  • +
  • -

#12 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 376
  • Joined: 04-January 11

Re: string error in c#

Posted 18 September 2012 - 01:12 AM

I would like to note these lines:

Console.WriteLine("Your teacher is Balkan");  
teacher = Balkan;



You do not have a variable Balkan. Instead, you want it to be inserted to the string variable, teacher, as a string right? So you have to enclose it in quotation marks.

teacher = "Balkan";



Same should be done in the following lines:

Console.WriteLine("Your teacher is Artrix");  
teacher = Artrix;  



Code should be
teacher = "Artrix";



This should insert proper values to your teacher variable.

This post has been edited by November-06: 18 September 2012 - 01:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1