2013-03-01 50 views
-1
namespace ThetwelveLabors1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("Welcome to Mythology 101 class, today i will ask you about 10 of the 12 labors of Hercules."); 
      Console.WriteLine("what was the first labor of Hercules?"); 
      Console.ReadLine();    
     }  
    }    
} 

這是我當前的代碼。我正在嘗試插入地點以允許用戶輸入。一旦問題得到妥善的回答,程序應該問下一個問題等等10個問題,然後有退出條件。我需要幫助檢索答案陳述

+6

什麼是你的問題? – 2013-03-01 22:55:43

+5

歡迎來到StackOverflow。恐怕我們不是代碼寫作服務,我們也不會爲你做功課。 :-)請努力弄清楚你自己。如果您遇到了您編寫的代碼問題(一旦您寫了一些代碼),那麼您可以回到這裏,詢問關於這些問題的具體問題併發布代碼。那麼我們很樂意嘗試和幫助。祝你好運。 :-) – 2013-03-01 22:56:50

+3

提示:'Console.ReadLine()'返回一個字符串。用它做點什麼。 – 2013-03-01 22:57:01

回答

2
Console.WriteLine("What is your favorite color?"); 
string answer = Console.ReadLine(); 

answer將包含任何用戶類型。

這會給你他們的答案的一個問題。

所以你可以做一個大的「if/else」聲明或switch

如果你想關閉程序,例如:

Console.WriteLine("Type exit to close the program"); 
string answer = Console.ReadLine(); 

if(answer.ToLower() == "exit") 
    Environment.Exit(0); 
2

如果我是你,我首先實現包含每個問題的數組:

String Questions[] = {"What was the first labor of Hercules"?,... }; // etc etc

String Answers[] = {"The right answer", "The right answer"};

然後一個for each loop,循環通過每個問題。在foreach循環中,while循環在回答不正確時循環。

如果用戶通過Console.Readline()輸入的值等於Answers數組中的對應值,則用戶已猜對並且可以將某些布爾值設置爲true,允許while循環結束,程序進入下一個問題。

當foreach循環結束時,程序將終止。

注意我沒有給你一段有用的代碼,因爲你需要自己解決這個問題。如果您有任何問題,可以隨時問另一個問題,而是盡力去實現這個:)

+2

+1爲「有用代碼的廢品」方法 – 2013-03-01 22:59:11

+0

有用的代碼或不,我只是想讓我的腳在門口,所以我可以花大部分時間用循環編碼 – user2125304 2013-03-01 23:11:13

+0

我明白了。這就是爲什麼我不只是想把代碼拋給你,而是讓你有機會發展自己的理解。正如我所說,歡迎您提出您需要的任何問題,以幫助您取得進展。 :) – christopher 2013-03-01 23:12:40

0

試試這個

static void Main(string[] args) 
    { 
     Console.WriteLine("Welcome to Mythology 101 class, today i will ask you about 10 of the 12 labors of Hercules."); 
     Console.WriteLine("what was the first labor of Hercules?"); 
     while (Console.ReadLine() != "Killing some lion") 
     { 
      Console.WriteLine("nope"); 
     } 

     Console.WriteLine("Correct!"); 
     Console.WriteLine(); 

     Console.WriteLine("What was the second labor of Herclules?"); 
    } 
+1

我認爲這個解決方案意味着大量的重複代碼。 – christopher 2013-03-01 23:02:04

+0

@ChrisCooney而不是什麼?一個重複的資源文件?你認爲在他自己做任何事情之前,我們需要教他如何提取它作爲一種方法? – 2013-03-01 23:04:06

+0

謝謝薩姆幫我把腳放在門上,這是我所需要的。我欣賞它 – user2125304 2013-03-01 23:04:42