Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Place variables in a list and rank them as output results

Status
Not open for further replies.

may5567

IS-IT--Management
Nov 29, 2005
1
GB
Hi there,

I am currently using one of your free downloads. I was wondering if you can be of help.

I have 5 variables

M1=5
M2=6
M3=8
M4=9
M5 =10

These variables are returned from user input. I need to put them in a list,rank them as highest value at top and lowest value at botton and extracted from list to be used sepeately.

Can you help !

Regards,

DAN
 
Hello. How is this program?
I am using Amzi Prolog.

test :-
write('Enter M1: '),
read(M1),
write('Enter M2: '),
read(M2),
write('Enter M3: '),
read(M3),
write('Enter M4: '),
read(M4),
write('Enter M5: '),
read(M5),
sort([M1, M2, M3, M4, M5], X),
myrev(X, R),
writedown(R).

myrev(X, R) :-
myrev2(X, [], R).
myrev2([], Y, Y).
myrev2([X1|XR], Y, R) :-
myrev2(XR, [X1|Y], R).

writedown([X|Y]) :-
write(X),
nl,
writedown(Y).

example:

?- test.
Enter M1: 31.
Enter M2: 4.
Enter M3: 15.
Enter M4: 92.
Enter M5: 6.
92
31
15
6
4
no

?- test.
Enter M1: 2.
Enter M2: 7.
Enter M3: 1.
Enter M4: 8.
Enter M5: 2.
8
7
2
2
1
no
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top