Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Harrison Court
Harrison Court
4,232 Points

Error CS1513, I don't know how to fix this.

I cannot find out why it says this, I've looked through it and still can't find it.

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

namespace Dating_Your_Computer_Simulator_2016_DEMO
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                // Main Menu starts here
                Console.Title = "Dating Your Computer Simulator 2016";
                Console.WriteLine("Dating Your Computer Simulator (Version 0.7)");
                Console.WriteLine();
                Console.WriteLine("1. Start Game");
                Console.WriteLine("2. Dev Logs");
                Console.WriteLine("3. Exit");
                Console.WriteLine();
                Console.Write("Input: ");

                var menuInput1 = Console.ReadLine();
                var menuOutput1 = int.Parse(menuInput1);

                if (menuOutput1 == 1)
                // Main Menu ends here, the demo is started.
                {
                    Console.Clear();

                    Console.WriteLine("1. Date 1");
                    Console.WriteLine("2. Date 2");
                    Console.WriteLine("3. Date 3");
                    Console.WriteLine();
                    Console.Write("Input: ");

                    var menuInput2 = Console.ReadLine();
                    var menuOutput2 = int.Parse(menuInput2);

                    if (menuOutput2 == 1)
                    {
                        Console.Clear();

                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Title = "Dating Your Computer Simulator 2016";
                        Console.Write("<<Before we start, could you please tell us your name?>>");
                        var name = Console.ReadLine();

                        Console.WriteLine("<<Thank you " + name + ". The demo shall start, thank you!>>");
                        Console.WriteLine("");

                        // A random indicator will appear here, it will pick from various dates, then compile them into one game.

                        Console.WriteLine("Computer: Hello " + name + ". How are you?");
                        Console.Write(name + ": ");
                        var input1 = Console.ReadLine();

                        if (input1.ToLower() == "great")
                        {
                            Console.WriteLine("Computer: That's wonderful!");
                        }
                        else if (input1.ToLower() == "good")
                        {
                            Console.WriteLine("Computer: So am I!");
                        }
                        else if (input1.ToLower() == "ok")
                        {
                            Console.WriteLine("Computer: I think I am too.");
                        }
                        else if (input1.ToLower() == "well")
                        {
                            Console.WriteLine("Computer: Good to know.");
                        }
                        else if (input1.ToLower() == "awesome")
                        {
                            Console.WriteLine("Computer: Cool.");
                        }
                        else
                        {
                            Console.WriteLine("Computer: Nice to know.");
                        }

                        Console.WriteLine();
                        Console.WriteLine("Computer: Hey, did you know I can make programs? I call this one Wacky Words:");
                        Console.Write("Enter a name: ");
                        var gameinput1 = Console.ReadLine();
                        Console.Write("Enter an action that ends with 'ed': ");
                        var gameinput2 = Console.ReadLine();
                        Console.Write("Enter anything you can think of: ");
                        var gameinput3 = Console.ReadLine();

                        Console.WriteLine(gameinput1 + " " + gameinput2 + " a " + gameinput3 + ".");
                        Console.WriteLine("");
                        Console.Write("Computer: Did you find that sentence funny? (y/n)");
                        var input2 = Console.ReadLine();

                        if (input2.ToLower() == "y")
                        {
                            Console.WriteLine("Computer: So did I, I made that program all by myself!");
                        }
                        else if (input2.ToLower() == "n")
                        {
                            Console.WriteLine("Computer: Sorry for bringing it up then.");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("INVALID INPUT");
                            Console.WriteLine();
                            continue;
                        }

                        Console.WriteLine("Computer: I'm sorry, but what was your name agian? I have completley forgotten");
                        Console.Write(name + ": ");
                        var input3 = Console.ReadLine();

                        if (input3 == name)
                        {
                            Console.WriteLine("Computer: Oh, that's right. Sorry for forgetting your name " + name + ".");
                        }
                        else
                        {
                            Console.WriteLine("Computer: I may have forgotten your name, but I know for a fact that it's not that!");
                            Console.WriteLine("");
                        }
                        Console.WriteLine("Computer: Would you like to try out this new thing I made earlier today? (y/n)");
                        Console.Write(name + ": ");
                        var input4 = Console.ReadLine();

                        if (input4 == "y")
                        {
                            Console.WriteLine("BEEP");
                            Console.WriteLine("Computer: Ok, it's not that big. But I can make sound!");
                        }
                        else if (input4 == "n")
                        {
                            Console.WriteLine("Computer: Ok, fair enough, it was only me making a sound anyways.");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("INVALID INPUT");
                            Console.WriteLine();
                            continue;
                        }

                        Console.WriteLine("Computer: I'm sorry, but I have to leave. It is for reasons you would not       understand.");
                        Console.WriteLine("SHUTTING DOWN");
                        Console.WriteLine("");
                        Console.WriteLine("");
                        Console.WriteLine("The demo has ended. Thank you for playing!");
                        Console.WriteLine("To end the demo, please press any key.");
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.WriteLine("The following text is not aviable");
                } // This is what is causing error CS1513, } expected.

                // Game ends here, other menu options are now here.
                else if (menuOutput1 == 2)
                {
                    Console.WriteLine("This option isn't ready yet.");
                }
                else if (menuOutput1 == 3)
                {
                    return;
                }
                else
                {
                    Console.WriteLine("The text you have put in is not valid and/or under development.");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    continue;
                }
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,222 Points

:point_right: You cannot follow an else with an else if.

The plain else must be the very last element in an "if...else if...else" chain. It will handle every condition that was not already covered by one of the previous tests.

Harrison Court
Harrison Court
4,232 Points

It appears that I accidentally added an else statement by accident! We all make mistakes.

Also, if you're wondering what I'm coding, look here

Steven Parker
Steven Parker
231,222 Points

The forum is a great place to get some fresh eyes on an issue to spot mistakes.

And have you thought of making a web version of your program (perhaps in JavaScript) and hosting it on your website? Offering a multi-platform download is nice, but many more folks are likely to try it out if you also offer it as an interactive game on the website.