input - Cant get to second read [Prolog] -


im having trouble these reads, can read first value, doesn't print second write , goes menu:

adicionar_viagens :- write('nova partida:'),nl, read(nova_partida),nl, write('novo destino:'),nl, read(novo_destino),nl, write('hora partida:'),nl, read(nova_hora_partida),nl, write('novo chegada:'),nl, read(novo_hora_chegada),nl, write('preco:'),nl, read(novo_preco),nl. 

in prolog, variables start either underscore or upper case letter. in argument read/1 calls you're using atoms (i.e. constants). thus, the calls succeed if term read unifies atoms. calls fail if input else, making call adicionar_viagens/0 predicate fail , behavior you're observing. change code to:

adicionar_viagens :-     write('nova partida:'), nl,     read(nova_partida), nl,     write('novo destino:'), nl,     read(novo_destino), nl,     write('hora partida:'), nl,     read(nova_hora_partida), nl,     write('novo chegada:'), nl,     read(novo_hora_chegada), nl,     write('preco:'), nl,     read(novo_preco), nl. 

but why read values if you're not doing values in clause? if want pass values caller of predicate, need add variables clause head:

adicionar_viagens(nova_partida, novo_destino, nova_hora_partida, novo_hora_chegada, novo_preco) :-     ... 

you can simplify variable names given of them refer new trip. example:

adicionar_viagens(partida, destino, hora_partida, hora_chegada, preco) :-     ... 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -