title: Prolog Power Function
body: <p>I am new to Prolog and while I can understand the code, I find it hard to create a program. I am trying to create a function that takes an integer and return 2^(integer) example pow(4) returns 16 (2^4). I also need it to be in a loop to keep taking input until user inputs negative integer then it exits.</p>
  
  <p>In this example, C is counter, X is user input, tried to include variable for output but cant think how to integrate it.</p>
  
  <pre><code>pow(0):- 0.
  pow(1):- 2.
  pow(X):-
     X &gt; 1, 
     X is X-1,
     power(X),
     C is X-1,
     pow(X1),
     X is 2*2.
  pow(X):- X&lt;0, C is 0.
  pow(C).
  </code></pre>