2013-04-10 49 views
4

我有一個問題,試圖使一個小的應用程序來解決Project Euler Problem #1問題試圖解決項目歐拉#1

每當我試圖運行它,它會返回0,而不是233168.

我不一定要找一個絕對的答案,只是一些提示,我努力學習。

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

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      int x; 
      List<int> listOne = new List<int>(); 
      for (x = 1; x < 1000; ++x) 
      { 
       if(x%3 == 0 || x%5 == 0) 
       { 
        listOne.Add(x); 
       } 
       Console.WriteLine(listOne.Sum()); 
       Console.ReadLine(); 
      } 
     } 
    } 
} 
+0

@ MD.Unicorn哈哈,對不起,我不是故意重寫你的格式編輯。當你把你放進去的時候,我正在編輯中:/我會把它捲成一個新的。 – 2013-04-10 04:13:17

+0

我對格式不好感到非常抱歉,我會記住我的下一篇文章。謝謝你的提示! – kmartmvp 2013-04-10 04:16:02

+0

@ user2264393這並沒有那麼糟糕,我們只是將它整理爲未來的人,他們可能也會遇到問題1的問題:) – 2013-04-10 04:18:07

回答

5

爲了幫助您學習,我不打算提供確切的答案。

看看您的Console.WriteLine()聲明的範圍。我的猜測是,當你認爲它應該是沒有運行的時候。

+0

哇,你說得對,我不知道我是怎麼看的。謝謝!現在它返回的數字太大了,但我會盡力找出一個。 – kmartmvp 2013-04-10 04:11:52

+0

@ user2264393我的榮幸!很高興看到你解決了它! – 2013-04-10 04:16:15