Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

I am using Curly Braces wrong, but where?

curly braces switch statement

Best Answer Chanito, 08 November 2015 - 10:15 AM

Got it working, here is the code:

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

namespace The_Switch_Statement_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Är ditt namn Yulieth (Ja/Kanske/Nej)");                      //Prints
            string input = Console.ReadLine();                                              //Reads the user input
            switch (input.ToLower())                                                        //Converts the input into lowercase
            {

                case "ja":                                                                      //Checks if it is true
                case "kanske":
                    Console.WriteLine("Hej Yulieth!");                                          //If it is true, WriteLine "Bra!"
                    break;                                                                      //If it is NOT true, continue to the next option

                case "nej":
                    Console.WriteLine("Stick då!");
                    break;

                default:
                    Console.WriteLine("Kan du inte Svenska eller?");
                    break;

            }
        }
    }
}
Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 Chanito

Chanito

    CC Newcomer

  • Member
  • PipPip
  • 14 posts

Posted 08 November 2015 - 09:58 AM

Hey! Just started to learn C# and i know i am using the curly braces wrong, could someone point to me where and why i am using them wrong, and how am i supposed to know where to put my code in the future? I appreciate any help.

 

Thank you!

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

namespace The_Switch_Statement_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Är ditt namn Yulieth (Ja/Kanske/Nej)");
            string input = Console.ReadLine();
            switch (input.ToLower())
            { }
           
            case "Ja":
            case "Kanske":
                Console.WriteLine("Bra!");
                break;
            
            case "Nej":
            Console.WriteLine("Synd!");
                break;

            default:
            Console.WriteLine("Du skrev fel?");
                break;

        }
    }
}



#2 Chanito

Chanito

    CC Newcomer

  • Member
  • PipPip
  • 14 posts

Posted 08 November 2015 - 10:15 AM   Best Answer

Got it working, here is the code:

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

namespace The_Switch_Statement_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Är ditt namn Yulieth (Ja/Kanske/Nej)");                      //Prints
            string input = Console.ReadLine();                                              //Reads the user input
            switch (input.ToLower())                                                        //Converts the input into lowercase
            {

                case "ja":                                                                      //Checks if it is true
                case "kanske":
                    Console.WriteLine("Hej Yulieth!");                                          //If it is true, WriteLine "Bra!"
                    break;                                                                      //If it is NOT true, continue to the next option

                case "nej":
                    Console.WriteLine("Stick då!");
                    break;

                default:
                    Console.WriteLine("Kan du inte Svenska eller?");
                    break;

            }
        }
    }
}