-1
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace LittleQuizworld_3
{
    class Program
    {
    public string QuestionText; //Actual question text.
    public string[] Choices; //Array of answer from which user can choose.
    public int Answer; //Index of correct answer with Choices.



    static void Main(string[] args)

    {

        int correct = 0;
        int iChoice =0;

        Console.WriteLine("Hello Welcome to Litte Quiz World, We hope you will have fun here");
        Console.WriteLine("Please press enter to continues :) ");
        Console.ReadLine();
        while (iChoice != 4)
        {
        Console.WriteLine("Please select the following");
        Console.WriteLine("1.Play Game");
        Console.WriteLine("2.Future game");
        Console.WriteLine("3.Credits");
        Console.WriteLine("4.Exit");
        Console.ReadLine();
        iChoice = Convert.ToInt32(Console.ReadLine());



          using (StreamReader sr = new StreamReader("./quiz.txt"))
        {



           switch (iChoice)
           {

         case 1:

            while (!sr.EndOfStream)
            {
                Console.Clear();
                for (int i = 0; i < 5; i++)
                {
                    String line = sr.ReadLine();
                    if (i > 0)
                    {
                        if (line.Substring(0, 1) == "#") correct = i;
                        Console.WriteLine("{0}: {1}", i, line);
                    }
                    else
                    {
                        Console.WriteLine(line);
                    }
                }

                for (;;){
                {
                    Console.Write("Select Answer: ");
                    ConsoleKeyInfo cki = Console.ReadKey();
                    if (cki.KeyChar.ToString() == correct.ToString())
                    {
                        Console.WriteLine(" - Correct!");
                        Console.WriteLine("Press any key for next question...");
                        Console.ReadKey();

                    }
                    else
                    {
                        Console.WriteLine(" - Try again!");
                        Console.Clear();
                    }




                    case 2:

                    if (iChoice == 2)
                    {
                        Console.WriteLine("Future game of Little Quiz World");
                        Console.WriteLine("Little Quiz Would will continues working on the patch for this game");
                        Console.WriteLine("Also the new game which is planned will be call BattleShip World beta testing will be very soon ");
                        Console.WriteLine("Please stick close to us ");
                        Console.ReadLine();
                    }
                            break;
                    case 3:
                    if (iChoice == 3)
                    {
                        Console.WriteLine("Credit");
                        Console.WriteLine("We hope you enjoy the game and please feel free to give us feeback at email : tonycheung2006@hotmail.co.uk");
                        Console.ReadLine();
                    }
                    break;


                        }
                    }
                }
             }
            }
        }

    }
}

ちょっとしたクイズ ゲームとメニュー システムを作成しましたが、case 文が機能していないようです。

4

4 に答える 4

0

中括弧のバランスはさておき、ケース 2 の下に if (iChoice==2) があるのは冗長であることに注意してください: switch ステートメントが iChoice にあるためです。iChoice==3 についても同様です。

申し訳ありませんが、私はC#の初心者です。

于 2009-12-17T05:52:09.973 に答える
0

中括弧のバランスはさておき、 switch ステートメントが on であるため、if (iChoice==2)underを持つことは冗長であることに注意してください。についても同様です。case 2:iChoiceiChoice==3

編集: 明確にするために、書く必要があります

case 2:
    if (iChoice == 2)
    {
        //...
    }

なので

case 2:
    //...

しかし、これがコードのコンパイルを妨げているわけではありません。他の人が指摘しているように、中かっこのバランスが取れておらず、ケースステートメントの一部をループ内に入れていますが、他のステートメントはそうではありません。

于 2009-12-17T05:06:44.713 に答える