![]() ![]() |
Sep 20 2004, 07:31 AM
Post
#1
|
|
|
New Member ![]() Group: Members Posts: 3 Joined: 20-September 04 Member No.: 1,751 ![]() |
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 |
|
|
|
Sep 20 2004, 10:16 AM
Post
#2
|
|
![]() Boss, my code's compiling (xkcd) Group: Admins Posts: 10,440 Joined: 19-September 01 Member No.: 1 ![]() |
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), "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 |
|
|
|
Sep 20 2004, 11:49 AM
Post
#3
|
|
|
New Member ![]() Group: Members Posts: 3 Joined: 20-September 04 Member No.: 1,751 ![]() |
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, |
|
|
|
Sep 20 2004, 05:13 PM
Post
#4
|
|
![]() Boss, my code's compiling (xkcd) Group: Admins Posts: 10,440 Joined: 19-September 01 Member No.: 1 ![]() |
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), "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 |
|
|
|
Sep 21 2004, 07:18 AM
Post
#5
|
|
|
New Member ![]() Group: Members Posts: 3 Joined: 20-September 04 Member No.: 1,751 ![]() |
thanks
bubble sort is already in my mind but it's not perfect |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 23rd May 2013 - 12:40 PM |