2uzhan.com
Advertisement
Now Place:2uzhan.com » I have some syntax errors I can't figure out.

I have some syntax errors I can't figure out.

Software Development @ August 20, 2008   Views:0

I was hoping you guys could help me out as you have in the past. I am kind of new to C# coming from C++.
I get two of each of these errors.

C:\Users\Hector Rosario\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs(51,39): error CS1518: Expected class, delegate, enum, interface, or struct
C:\Users\Hector Rosario\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs(57,9): error CS1022: Type or namespace definition, or end-of-file expected

Here is what I am working on

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

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {

            string Name;
            bool Life;
           string choose;

            string Sex;
            Console.WriteLine("Welcome to Hector Rosario's Character Generator.");
              Console.Write("Please enter your name: ");
            Name = Console.ReadLine();
            Console.WriteLine("Your character's age is {0}", age);
            int age = GenerateRandomInteger(10, 40);
            Console.WriteLine("Do you want your character to be male or female?\n Prees m or f to make your choice.");
            switch (choose)
                {
                    case "m":
                        Sex = "Your character is male";
                        break;
                    case "f":
                        Sex = "Your character is female";
                        break;

                       default:
                        Sex = "I'm sorry but uh... last I checked there were only two sexes, male and female.";
                        break;
                }//end switch statement

                Console.WriteLine();
                Console.WriteLine(Sex);
                Console.WriteLine();
                Console.WriteLine("Press [ENTER] to Exit");
                Console.ReadLine();

}

        }//end class "switchStatement
    private static int GenerateRandomInteger(int intMin, int intMax)
        {
            //Create a new instance of the class Random
            Random randomNumber = new Random();
            //Generate a random number using intMin as the minimum and intMax as the maximum
            return randomNumber.Next(intMin, intMax);
        }//end of number generator

        }

    }

--------------Solutions-------------

Never mind, I fixed it. This is how I did it.

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {

            string Name;
            bool Life;
           string choose = "Ok, ";
           int age = GenerateRandomInteger(10, 40);

            string Sex;
            Console.WriteLine("Welcome to Hector Rosario's Character Generator.");
              Console.Write("Please enter your name: ");
            Name = Console.ReadLine();
            Console.WriteLine("Your character's age is {0}", age);

            Console.WriteLine("Do you want your character to be male or female?\n Prees m or f to make your choice.");

            switch (choose)
                {
                    case "m":
                        Sex = "Your character is male";
                        break;
                    case "f":
                        Sex = "Your character is female";
                        break;

                       default:
                        Sex = "I'm sorry but uh... last I checked there were only two sexes, male and female.";
                        break;
                }//end switch statement

                Console.WriteLine();
                Console.WriteLine(Sex);
                Console.WriteLine();
                Console.WriteLine("Press [ENTER] to Exit");
                Console.ReadLine();

}
       private static int GenerateRandomInteger(int intMin, int intMax)
        {
            //Create a new instance of the class Random
            Random randomNumber = new Random();
            //Generate a random number using intMin as the minimum and intMax as the maximum
            return randomNumber.Next(intMin, intMax);
        }//end of number generator
        }//end class "switchStatement

        }

It didn't have the intended results I wanted but it compiled. I can get to to making that switch working now!

I'm attempting to simplify my fundraising page, and would like to show exactly how much each donation would help us out. I've listed the options below, but I would like ...

Write a java program that asks a person for his height (in meters) and weight (in kilograms) and
outputs one of the messages: underweight, normal, or obese, using the BMI ...

Before I get into the specific issues, I want to provide some other details:

  • Normally, I work on a live, paid server (even in dev); I realize that is ...
Tags:
© 2018 2uzhan.com Contact