示例#1
0
文件: Program.cs 项目: asb43/PCE_02
        public void RunExercise()
        {
            Console.WriteLine("About to do the \"Conditional Statements\" exercise");
            Conditional_Methods cm = new Conditional_Methods();

            cm.UsingIf();
            cm.UsingIfElse();
            cm.UsingSwitch();
        }
示例#2
0
        public void RunExercise()
        {
            Console.WriteLine("About to do the \"Conditional Statements\" exercise");
            Conditional_Methods cm = new Conditional_Methods();
            //int userChoice;
            //Int32.TryParse(Console.ReadLine(), out userChoice);
            int userChoice = 11;

            cm.UsingIf();
            if (userChoice > 10 || userChoice < 0)
            {
                Console.WriteLine("please enter a number between 0 and 10");
            }
            if (userChoice == 0)
            {
                Console.WriteLine("You need to talk to the professor immediately!");
            }
            if (userChoice == 1)
            {
                Console.WriteLine("You need to study a lot more!");
            }
            if (userChoice == 2)
            {
                Console.WriteLine("If you keep working at this, you'll do better!");
            }
            if (userChoice == 3)
            {
                Console.WriteLine("If you keep working at this, you'll do better!");
            }
            if (userChoice == 4)
            {
                Console.WriteLine("If you keep working at this, you'll do better!");
            }
            if (userChoice == 5)
            {
                Console.WriteLine("You've gotten the hang of this, but with practice, I'm sure you can do even better!");
            }
            if (userChoice == 6)
            {
                Console.WriteLine("You've gotten the hang of this, but with practice, I'm sure you can do even better!");
            }
            if (userChoice == 7)
            {
                Console.WriteLine("Nice job, but don't let yourself slack!");
            }
            if (userChoice == 8)
            {
                Console.WriteLine("Nice job, but don't let yourself slack!");
            }
            if (userChoice == 9)
            {
                Console.WriteLine("Very nice job – keep up the good work!");
            }
            if (userChoice == 10)
            {
                Console.WriteLine("Perfect!");
            }

            cm.UsingIfElse();
            if (userChoice == 0)
            {
                Console.WriteLine("You need to talk to the professor immediately!");
            }
            else if (userChoice == 1)
            {
                Console.WriteLine("You need to study a lot more!");
            }
            else if (userChoice == 2)
            {
                Console.WriteLine("If you keep working at this, you'll do better!");
            }
            else if (userChoice == 3)
            {
                Console.WriteLine("If you keep working at this, you'll do better!");
            }
            else if (userChoice == 4)
            {
                Console.WriteLine("If you keep working at this, you'll do better!");
            }
            else if (userChoice == 5)
            {
                Console.WriteLine("You've gotten the hang of this, but with practice, I'm sure you can do even better!");
            }
            else if (userChoice == 6)
            {
                Console.WriteLine("You've gotten the hang of this, but with practice, I'm sure you can do even better!");
            }
            else if (userChoice == 7)
            {
                Console.WriteLine("Nice job, but don't let yourself slack!");
            }
            else if (userChoice == 8)
            {
                Console.WriteLine("Nice job, but don't let yourself slack!");
            }
            else if (userChoice == 9)
            {
                Console.WriteLine("Very nice job – keep up the good work!");
            }
            else if (userChoice == 10)
            {
                Console.WriteLine("Perfect!");
            }
            else
            {
                Console.WriteLine("please enter a number between 0 and 10");
            }

            cm.UsingSwitch();
            switch (userChoice)
            {
            case 0:
                Console.WriteLine("You need to talk to the professor immediately!");
                break;

            case 1:
                Console.WriteLine("You need to study a lot more!");
                break;

            case 2:
            case 3:
            case 4:
                Console.WriteLine("If you keep working at this, you'll do better!");
                break;

            case 5:
            case 6:
                Console.WriteLine("You've gotten the hang of this, but with practice, I'm sure you can do even better!");
                break;

            case 7:
            case 8:
                Console.WriteLine("Nice job, but don't let yourself slack!");
                break;

            case 9:
                Console.WriteLine("Very nice job – keep up the good work!");
                break;

            case 10:
                Console.WriteLine("Perfect!");
                break;

            default:
                Console.WriteLine("please enter a number between 0 and 10");
                break;
            }
        }