Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I'm having some problems with the line "j >= j * n"
I get the following error:
Only assignment, call, increment, decrement, and new object expressions can be used as a statement.

and I am trying to, increment, j.

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

namespace Functions
{
    public class Factorial
    {
        // The "Calc" static method calculates the factorial value for the
        // specified integer passed in:
        public static int Calc(int i)
        {
            return ((i <= 1) ? 1 : (i * Calc(i - 1)));
        }
    }
}

namespace infini
{
    class infini
    {   
        static void Main(string[] args)
        {
            int n;
            int j;
            n = 3;

            Dictionary<string, int> d =
new Dictionary<string, int>();

            d.Add("A1", 0);

            List<int> range = new List<int>();
            for (int i = 1; i > 0; i++)
            {
                j = 1 - d["A1"] / Calc(n) ;
                while ((i * j) < 1)
                {
                    j >= j * n;
                }
            }

     

            
        }

        private static int Calc(int n)
        {
            throw new NotImplementedException();
        }

        public static int Factorial { get; set; }
    }
}
Posted
Comments
TRK3 26-Sep-12 18:18pm    
You are having a lot more than just problems with that one line.

The line itself is an expression that evaluates to true or false, but doesn't assign or increment anything.

If you want to increment j, then just write:

j++;

or

j = j + 1;

However, the whole Main() function spends a lot of time to accomplish absolutely nothing.

Go ahead and change the line to what I've suggested, then step through your function in a debugger and see what happens.

The error you get is because you don't actually 'do' anything, you only check.
>= means check if greater than, or equal to. It does not change j.
To inclement j you need to use something like below, depending on what you need to do.

C#
j = j + 1; //Add 1 to j, and store that in j
j += 1; //Add one to j, and store it in j (shorthand notation)
j++; //Increment j with 1 (even shorter shorthand notation)

//Or with n

j += n; //Add n to j, and store in j(same as j = j + n)
j *= n; //Multiply j with n, and store in j (same as j = j * n)


Hope this helps you on your way, if not, feel free to post a comment.
 
Share this answer
 
The error message is clear:
C#
j >= j * n;

is NOT a valid statement.
What are you trying to do (you know, you may just use the (valid) statement
C#
j++;

for incrementing j).


BTW there is NO "setting j greater than or equal to i", but only "testing if j is greater or equal to i" (at least in the programming languages I know).
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 26-Sep-12 18:28pm    
OP is now properly brain-washed with the beginner's stuff, my 5. :-)
One more note from me, please see Solution 3.
--SA
In addition to what was already said, j >= j * n is strictly equivalent to n <= 1 || j == 0, which is more effective because the second part may not be checked in most cases or need not to be included in the expression because it is so defined in code.

—SA
 
Share this answer
 
Comments
TRK3 26-Sep-12 19:44pm    
Actually, it's equivalent to (n < 1 && j > 0) || (j < 0 && n > 1).

But n = 3, and doesn't change, so it's just j > 0.

On the otherhand, j is never asigned a value since the Calc(n) call in the assignment to j throws and exception. So the whole thing can be optimized away as:

throw new NotImplementedException();
Sergey Alexandrovich Kryukov 26-Sep-12 19:47pm    
I like the idea :-)
--SA
brazguna 26-Sep-12 22:20pm    
from math import factorial
#from math import pow

n = 3
d = {"A1":None, "B1":None}
print "To begin type: 'infinity(#)'. \n'#' is any number you desire. \n\nRemember to press Ctrl+C to stop."

def infinity(n):
for i in range(1):
j=(1-pow(d["A1"], n)/factorial(n))
while (i*j)<1:
j+=j*n
print j-1

d["A1"] = 0
d["B1"] = `1-pow(d["A1"], (infinity(n))/factorial(infinity(n)))`


This is the original python code I am trying to write into C#.
It makes an infinite loop that creates output like the following:

3
15
63
255
1023
4095
16383
65535
262143
1048575
4194303
16777215
67108863
268435455
1073741823
4294967295
Sergey Alexandrovich Kryukov 27-Sep-12 0:46am    
And?..
--SA
Sergey Alexandrovich Kryukov 27-Sep-12 0:49am    
Well, here is the advice: just write code out of mathematical understanding of the problem, don't try to "write into C#" or translate.
The problem is more then trivial.
By the way, to work with big numbers (as you can do in Python), don't use integer type, use System.Numerics.BigInteger (see).
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900