views:

61

answers:

1
input = *
value = 3
output = ***(3 star)

use prolog to write out the coding when key in value is 3 than the output is ***(3star) or when key in value is 5 than output is *****(5 star).

so i want to ask what are the coding in prolog for this question.

my answer is like below but cannot compile and have error. can check for me??

start:-
     write('input:'),
     read(X),
     nl,
     write('value:'),
     read(Y),
     nl.
end_of_file.
+1  A: 

I was able to run this program just fine (I have GNU Prolog 1.3.0). (Although it does not fully fullfill your specifications, it's not quite done yet).

Like this, here's how it runs like :

me@consoleterminal$> prolog
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- ['/home/myfolder/myprogram.pl'].
compiling /home/myfolder/myprogram.pl for byte code...
/home/myfolder/myprogram.pl:1-7: warning: singleton variables [X,Y] for start/0
/home/myfolder/myprogram.pl compiled, 8 lines read - 533 bytes written, 5 ms

yes
| ?- start.
input:3.

value:3.


yes
| ?-
rlb.usa
thanks for your answer but i also cannot understand. can you explain more detail.
Tonberry
@Tonberry - It runs, no errors. But it needs more work to answer your homework(?) question.
rlb.usa
Can you please tell us what error messages you are getting?
rlb.usa
that's is no error already but output not same with the answer.i want the output is like below:| ?- start.input:|: *.value:3.***but when i compile it is like below:| ?- start.input:|: *.value:3.* Syntax Errorso how can i get my answer.thanks for your replay.
Tonberry
You need to do more work - learn Prolog some more. I'm sorry, I can't just "give you the codes". If you have specific questions, we can help you.
rlb.usa
thank you so much^.^
Tonberry