CyberiaPC.com Community Forums Main Page
RSS Feeds: Late(st) News | Zenith Picture Gallery | Most Recent Community Topics | Tips, Tricks and Other Useful Stuff

Welcome Guest ( Log In | Register )

> two max, c++
almarkhi
post Sep 20 2004, 07:31 AM
Post #1


New Member
*

Group: Members
Posts: 3
Joined: 20-September 04
Member No.: 1,751

Bahrain




hi


am a new member here and am a beginner in c++
just wondering if you have ten variables how you can get the two maxs ?

Mohd,
bye
Go to the top of the page
 
+Quote Post
Start new topic
Replies (1 - 4)
usr.c
post Sep 20 2004, 10:16 AM
Post #2


Boss, my code's compiling (xkcd)
Group Icon

Group: Admins
Posts: 10,440
Joined: 19-September 01
Member No.: 1

Nothing Selected




Loop through all the variables (assuming they're stored in an array), checking to see if each one is bigger than the one before it. If it is, replace your 'max' variable with that value.


--------------------


Things that I don't suck at: Photography (flickr, JPG Mag), Skydiving, Splitting atoms, Flying a space shuttle
"Don't bail; the best gold is at the bottom of barrels of crap!" -Randy Pausch
I have people-skills goddamnit! What is wrong with you people!!! | www.skyrill.com
Go to the top of the page
 
+Quote Post
almarkhi
post Sep 20 2004, 11:49 AM
Post #3


New Member
*

Group: Members
Posts: 3
Joined: 20-September 04
Member No.: 1,751

Bahrain




thanks ali for your response but i want two max not one
actually i want it in comparsion instead of array or pointer

i need the idea asap coz i have it as assignment that input student id then three test score and print the avereage of two best score

Ali where do u live in Bh?
regards,
Go to the top of the page
 
+Quote Post
usr.c
post Sep 20 2004, 05:13 PM
Post #4


Boss, my code's compiling (xkcd)
Group Icon

Group: Admins
Posts: 10,440
Joined: 19-September 01
Member No.: 1

Nothing Selected




In that case, look for the min instead using a similar method as the one I described above. Once you have that, take the average of the other two.

The alternative for n test grades would be to use a sorting algorithm (e.g. Bubble sort) and then pick the top two values.


--------------------


Things that I don't suck at: Photography (flickr, JPG Mag), Skydiving, Splitting atoms, Flying a space shuttle
"Don't bail; the best gold is at the bottom of barrels of crap!" -Randy Pausch
I have people-skills goddamnit! What is wrong with you people!!! | www.skyrill.com
Go to the top of the page
 
+Quote Post
almarkhi
post Sep 21 2004, 07:18 AM
Post #5


New Member
*

Group: Members
Posts: 3
Joined: 20-September 04
Member No.: 1,751

Bahrain




thanks
bubble sort is already in my mind but it's not perfect
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 19th May 2013 - 03:12 PM