none
Two Errors in my code please help! RRS feed

  • Question

  • So basically my first switch loops if you enter 2 and ends in you press 1

    also I cannot advance my code to the second static void

    Please help!

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

    namespace RUINGameFinial
    {
        class Program
        { 
            static void Main(string[] args)
            {
                gameTitle();
                first();
                second();
            }

            public static void gameTitle()
            {
                Console.WriteLine("Wellcome to RUIN!");
                Console.WriteLine("Its 1985 and the world is absolutely beyond fucked. The Russians and Americans finally got around to pulling the trigger. The world is a shell of what it was, the population has been reduced to about 1% of what it once was. Small pockets of the worlds former glory remain. You are a national guardsman stationed in Atlanta Georgia when the bombs dropped. The scattered national guard posts are the seeds of civilization. When the bombs fell the computer and phone lines between them all were broken. Your sergeant has assigned you to go from base to base across the nation and fix these downed lines. He assigns you to go to Nashville first and then keep moving west, your reward he states; upon your success Is a major promotion to sergeant so that he may retire peacefully to his farm. It is your duty private; and you are humanity's last hope to restore order to the wastelands.");
                Console.WriteLine("You find yourself inside the national guard camp. There are many rows of tents that survivors sleep in that for a village around the base itself. Down a central gravel pathway leads to a small market in the center of the tents, there are several stall selling various foods and weapons and other gear needed for survival outside of the camp walls.You make your way to the base building itself it is large,several stories tall and made of strong red brick. You approach the front guard and he tells you that your convoy vehicle has been fuelled and stocked around back of the base. You take your leave of him and slowly take a walk around back until you arrive at the last reaming jeep. Inside is enough food and water to get you to your next target, Nashville tennessee. You are also granted 30 ration coupons, which can be exchanged for gear and bases and are used as currency between bases and traders. You are given a shotgun and revolver. You exit the camp and head north!");
                Console.WriteLine("Press 'Enter' to begin.");
                Console.ReadLine();
                Console.Clear();
                first();
            }

            public static void first()
            {
                string choice;

                Console.WriteLine("You drive north untill seeing a small band of scavengers in a brokedown RV by the road they signal for you.(about 4 or so)");
                Console.WriteLine("1. Speed past them and leave them in the dust");
                Console.WriteLine("2. Pull over and help");
                Console.Write("Choice: ");
                choice = Console.ReadLine().ToLower();
                Console.Clear();

                switch (choice)
                {
                    case "1":
                        {
                            Console.WriteLine("You make extra effort to kick dust into thier faces as you drive");
                            Console.WriteLine("They throw muffled insults at you under the sound of your engine and throw thier hands up in frustration");
                            Console.WriteLine("Press 'Enter' to continue");
                            Console.ReadLine();
                            choice = Console.ReadLine().ToLower();
                            Console.Clear();
                            break;
                            second();

                        }
                    case "2":
            
                        Console.WriteLine("You bring your car to a stop behind the scavangers and decide to help them.");
                        Console.WriteLine("They seem to be a family,what you can assume is a mother,father daughter and son. The perfect post-nuclear family");
                        Console.WriteLine("Who you assume to be the father aproches you,Thank you for stoping he says, we ran out of gas halfway to a local scrapyard we were going to go comb trough,could you give us a hand? You give them some of your fuel and they thank you,giving you some bandages as a reward. Thank you for your help Gaurdsman! I Hope we meet again.");
                        Console.WriteLine("Press 'Enter' to continue");
                        Console.ReadLine();
                        Console.Clear();
                        break;
                        second();
                }
            }

            public static void second()
            {
                string choice;

                Console.WriteLine("You drive further north into the tennese farmland. Seeing that it is getting late,you decide");
                Console.WriteLine("1. Pull over and sleep on the road");
                Console.WriteLine("2. Pull into an abandoned farmhouse for the night");
                Console.Write("Choice: ");
                choice = Console.ReadLine().ToLower();
                Console.Clear();

                switch (choice)
                {
                    case "1":
                        {
                            Console.WriteLine("You pull your jeep over to the side of the road and make a bed in the back seat,arms around your shotgun like a dear teddy bear. You drift of to sleep...");
                            Console.WriteLine("You could have sworn in the night you heard some sort od growling but were to tired to ivestigate...");
                            Console.WriteLine("Press 'Enter' to continue");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                            

                        }
                    case "2":

                        Console.WriteLine("You pull your jeep into the farm house drive way and");
                        Console.WriteLine("You walk into the small,dusty farmhouse the door is unlocked.. ");
                        Console.WriteLine("You make your way upstairs and get into bed, you begin to does off into the night....");
                        Console.WriteLine("Press 'Enter' to continue");
                        Console.ReadLine();
                        Console.Clear();
                        break;

                }
                     }







        }
     }

    Wednesday, January 10, 2018 5:43 AM

Answers


  • also I cannot advance my code to the second static void

                                     

                switch (choice)
                {
                    case "1":
                        {

                          ...

                            Console.Clear();
                            break;
                            second();

                        }

    For one thing, a break will take place immediately and no code after
    it will be executed. Didn't the compiler give you a warning about
    unreachable code?

    - Wayne

    • Marked as answer by redcelt33.rm Wednesday, January 10, 2018 6:58 AM
    Wednesday, January 10, 2018 5:59 AM

All replies


  • also I cannot advance my code to the second static void

                                     

                switch (choice)
                {
                    case "1":
                        {

                          ...

                            Console.Clear();
                            break;
                            second();

                        }

    For one thing, a break will take place immediately and no code after
    it will be executed. Didn't the compiler give you a warning about
    unreachable code?

    - Wayne

    • Marked as answer by redcelt33.rm Wednesday, January 10, 2018 6:58 AM
    Wednesday, January 10, 2018 5:59 AM
  • Thank you!

    No it did not I will fix :D

    Wednesday, January 10, 2018 6:58 AM