944,108 Members | Top Members by Rank

Ad:
Oct 22nd, 2005
0

Algorithm problem

Expand Post »
Hi there. I'm Kurt!!
I have two algorithm problems.
I was wondering if you can check my answers for the first one and help me get a start with the second one:

1)Write an algorithm to compute the average of 5 numbers

Name: Ave5
Given: X1, X2, X3, X4, X5
Change: none
Intermediate: Total
Result: Average
Definition: Average:= Ave5 (X1, X2,X3,X4,X5)

METHOD

Get X1
Get X2
Get X3
Get X4
Get X5

Total = X1 + X2 + X3 + X4 + X5
Average = Total/5

Give Average





2) Write an algorithm to get the names and ages of two people. Return the name of the person who is older (in format "x is older than y", where x and y are the names of the two people), unless the two people are the same age, in which case, return the message "x is the same age as y.

I'm having trouble writing an algorithm for this particular case. It's more complicated than what I am used to. Can someone give me an idea on how to start a problem like this one ? I have made a couple of assumptions:
Name: PerAge
Givens: X, Y
Change: X,Y
Intermediate: Age
Result: none
Definition: Age =: PerAge (X,Y)

METHOD

Give X
Give Y

Well... I'm pretty lost at this point

Thank you advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
KultChyld is offline Offline
1 posts
since Oct 2005
Oct 22nd, 2005
0

Re: Algorithm problem

>I was wondering if you can check my answers for the first one and help me get a start with the second one
The first one looks fine. Your problems with the second one makes me wonder.

>It's more complicated than what I am used to.
So basically anything that has more than one branch of execution is too much for you. You're looking at three branches: the ages are equal, x is less than y, and x is greater than y. Do you know how to use an if..else?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jun 20th, 2010
-1
Re: Algorithm problem
can i ask if what is the meaning of algorithmic problem cause thats my assignment im 1st year college in asian institute of computer studies.. plz help me
Reputation Points: 9
Solved Threads: 0
Newbie Poster
reycarcillar is offline Offline
1 posts
since Jun 2010
Jun 20th, 2010
0
Re: Algorithm problem
Check equal case, if not equal then, if a is older than b declare a oldest otherwise declare b older.
Featured Poster
Reputation Points: 687
Solved Threads: 748
Industrious Poster
pyTony is offline Offline
4,208 posts
since Apr 2010
Jun 20th, 2010
0
Re: Algorithm problem
well all u gotto do , is to check the age of two people and print in the format asked
for example:
if (  x.age > y.age)
    cout<<x.name<<"is older than <<y.name;
else if ( x.age == y.age)
    cout<<x.name<<"is same age as "<<y.name;

well i am assuming ur doing using classes , it would be easier since the person will
share the same attributes so better to put in one class.
Reputation Points: 92
Solved Threads: 20
Posting Whiz
rahul8590 is offline Offline
351 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: How to meat people?
Next Thread in Computer Science Forum Timeline: A Text Editor





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC