Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » marlovebar
  • » Profile

Posts

Posts

Thank you! Works properly! current/smile

Thank you for the answer. The function is now loaded successfully, but now the problem is that  whichever number I enter, function gives me number 0 as a result...Should I use any other statement to avoid the 0 result?

Hello,

I'm a new Modelica user and I'm writing a code for factorial function in OMShell. However I came to a problem, which I don't know how to solve, since the next error keeps coming no matter what I do:

Error: No viable alternative near token: =

Here is the code I wrote:

function factorial
    input Integer n;
    output Integer y;
algorithm
    for i in 1:n loop
        if (n=0) then
        y := 0;
        else
        y := i*factorial(i-1);
        end if;
    end for;
end factorial;

I tried to erase and add semicolon in different places, but still did not work. Can somebody help me with this problem?

  • Index
  • » Users
  • » marlovebar
  • » Profile
You are here: