0
using System;
public class Test
{
    public static void Main()
    {
        int n = 600851475143;
        int x = 1;
        While (x<n)
        {
        if(n%x==0)
            {
                Console.WriteLine(x);
            }    
        x++;
        }    
    }    
}       

Gives me a { out of place error, but I can't see whats wrong. Anyone?

2 Answers2

6

While should not be capitalized, and your value of n is too large for an int.

You don't seem to have a problem with braces. If you fix those two errors it should compile.

Edit: The code file you posted is a completely different error than the one you posted in the question. A C# program can only have one entry point, which is what public static void Main() does. If you copy and pasted the method signature from the Program file it is not going to compile. Change Main to any other valid signature and it should compile.

Brandon
  • 68,708
  • 30
  • 194
  • 223
  • You're correct but I still get "Compilation failed: 1 error(s), 0 warnings Test.cs" Line 10 Column 8 - Unexpected symbol `{' –  Jul 18 '12 at 15:40
  • 4
    @idb, then that error is coming from somewhere other than what you've posted in your question. If I copy and paste it exactly as-is and fix those two errors, it compiles. – Brandon Jul 18 '12 at 15:41
  • if `while` is written correctly (i.e. in lowercase) you should not get this error. – CodesInChaos Jul 18 '12 at 15:41
  • 1
    With `While` capitalized, the compiler likely think it's a method call, and it does not understand the `{` immediately after the method call (no semicolon `;`). – Jeppe Stig Nielsen Jul 18 '12 at 15:42
  • 2
    That website shows a completely different error, caused by you having two `Main` functions in different files. But don't ask me how it's even possible to set multiple entry points in the first place. – CodesInChaos Jul 18 '12 at 15:44
2

While (x<n) should be while (x<n)

And you are assigining a long value to an int variable.

The maximum value an int varibale can hold is 2,147,483,647; So you may change that to long

long  n = 600851475143;
Community
  • 1
  • 1
Shyju
  • 214,206
  • 104
  • 411
  • 497