Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Urgent Major Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jess25




PostPosted: Thu Nov 28, 2002 1:37 pm   Post subject: Urgent Major Problem

I need major help on writing a program I've tried writing it but I'm having problems. The program should allow the user to input the value for several basketball players and their height in inches. I should be able to ask the user how many players are to be entered, and have the program convert the players' heights from inches to centimeters (2.2 cms per inch.)And calculating the average height for those players and output the tallest player.

Thanks
Sponsor
Sponsor
Sponsor
sponsor
FizixMan




PostPosted: Thu Nov 28, 2002 4:01 pm   Post subject: (No subject)

The best way to tackle this is to use an array. Have the user input the number of basketball players (and consequently the size of the array). When you get the integer input, you can declare the array with that variable:

var players:array 1..INPUT of real

Then, you need the user to input all the basketball player's heights which can be accomplished easily enough with a "for" loop. And in the same loop, you can figure out the tallest player and the average height. Just have one variable look for the tallest player while another one sums up all the heights (remember average is the sum of the heights divided by the number of players). Also remember to assign a value of zero to the maxheight before you start the loop

code:

maxheight:=0
for count:1..INPUT
get players(count)
sum+=players(count)
if maxheight<players(count) then
maxheight:=players(count)
end if
end for


Then at the end, you can output your numbers and multiply by 2.2 at the same time. I probably could have given you less code than this, but I'm pressed for time and it was just easier to post bits of the code.
Tony




PostPosted: Thu Nov 28, 2002 6:48 pm   Post subject: (No subject)

hey FixizMan, you forgot the fact that you can't add heights in "feet, inches" format...

Try adding 5 10 and 6 2, what do you get? 12!

To add them up (and to find the largest one), you gotta convert height to inches only. So

code:

get feet
get inches

inches = inches + 12*feet
//this is your total height


then when you found the average, you convert it to metric system:

code:
put averageHeight*2.2
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
FizixMan




PostPosted: Thu Nov 28, 2002 7:16 pm   Post subject: Re: Urgent Major Problem

jess25 wrote:
The program should allow the user to input the value for several basketball players and their height in inches.
Thanks

pshhhhhhhhhhhhhh
Look who's talking man... he didn't say anything about inputting it as feet and inches... just their height in inches... so Razz on you

haha; it's all good man.
Tony




PostPosted: Thu Nov 28, 2002 10:10 pm   Post subject: Re: Urgent Major Problem

FizixMan wrote:
jess25 wrote:
The program should allow the user to input the value for several basketball players and their height in inches.
Thanks



lol, read what you quote Exclamation
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
FizixMan




PostPosted: Fri Nov 29, 2002 2:42 am   Post subject: (No subject)

ummm..... *reads through the post again* I still don't see the word "feet" in it... so I dont' see where you're getting this from man... I imagine the input isn't feet & inches, JUST inches. So if they're 6'0", the input would be 72. I think that's what he means... but whatEVrrrrrrrrrr it could be either way I guess, and we got both possibilities covered...








(darn Imperial System... Razz )
Stuperman




PostPosted: Fri Nov 29, 2002 4:44 am   Post subject: (No subject)

one thing there is 2.5 cm in one inch.....
FizixMan




PostPosted: Fri Nov 29, 2002 1:47 pm   Post subject: (No subject)

Actually... it's 2.54 cm/inch Razz



(why are we still going on aboot this??? lol)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Nov 29, 2002 5:59 pm   Post subject: (No subject)

well I always thought it was 2.5... but the guy asked for 2.2, so meh... maybe he's from some remote place?

anyway, when you're asked for your height in inches, you usually use feet... but w/e... We already figured out this problem.

Just saying that if you're to look up some stats for b-ball players... their height would have feet Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
FizixMan




PostPosted: Sat Nov 30, 2002 6:18 pm   Post subject: (No subject)

but considering the difficulty (or rather, the simplicity) of it suggests that inputing both the feet and inches is a bit much over just inputing a single integer for the total inches.




(funny how we are still arguing over such a triviality... it's fun eh? Laughing )
Dan




PostPosted: Sat Nov 30, 2002 6:46 pm   Post subject: my god

this is going a litte nuts here, i think this is satring to be one of those topics that needs to be loked. oh well i kind of whont to see how long you guys are going to go on about this any way Wink
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Tony




PostPosted: Sat Nov 30, 2002 8:48 pm   Post subject: (No subject)

Dan, I don't think that locking the topic would do any good as a continue on topic might be created... Or I can just unlock the topic Wink

And yes, simplicity... You might as well ask the user to input all heights in cm right away and in order! I mean come on, the purpose of programming is to get computers to do the thinking for us, not make metters worse by making user figure out what to input.

I mean to enter the height in inches, you must first figure out what it is by converting feet to inches, in that case it would be easier to let computer do that for you. Twisted Evil
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
FizixMan




PostPosted: Sun Dec 01, 2002 6:12 am   Post subject: (No subject)

umm... umm... errr... uhhh... RATS! ... hmmm... Imperial system sucks! Metric FOREVER!!!!! *runs away*
Tony




PostPosted: Sun Dec 01, 2002 2:18 pm   Post subject: (No subject)

YES! I WIN! Twisted Evil

hehe, metric rocks, thast why the program converts feet to cm Wink

So you can stay and chill here @ SWAT.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: