Question Enter number, nothing happens?


New member
Oct 25, 2013
Austin Tx
Programming Experience
Hello, I'm relatively new to C#. I'm working on my computer science major and the only language I can safely say that I know fairly well is python (Though I have done stuff with C++ and Java). I chose C# because I like Windows and it looked like a good hybrid between Java and C++. Anyway, I had just finished a homework in python code, and tried implementing it in C# with my limited knowledge of this language and when I enter a value for the variable number, nothing happens. The console just stops working or something after I've entered the number at runtime. If anyone could help me understand what I did wrong I'd appreciate it very much. My code is in the attached file(formatting was weird in code tags):

Oh yeah, I'm new to the forums so... hi. I'll post an introduction later, this was just on my mind when I registered.


  • C#program.txt
    1.7 KB · Views: 42

wim sturkenboom

Well-known member
Aug 6, 2014
Roodepoort, South Africa
Programming Experience
Your program is hanging in this method.

public static int primeFactorPower(int n, int p)
    int count = 1;

    while (n % (Math.Pow(p, count)) == 0)
        count += 1;

    return count - 1;
If n==1 and p==1, the result of the modulo is always 0 (as 1^number always equals 1) and you get stuck in an endless loop.

On a side note, read up on comparison of doubles and floats; those types are not 100% accurate so the result of the modulo might be 0.00000000000000000000000001; close enough for us humans but not for computers ;)

// OOPS: as a newbie, I'm reviving old threads :(
Last edited:
Top Bottom