d2jsp
Gaming and Trading Community
Gaming and Trading Community
d2jsp Forums > Programmer's Haven > C/C++/C# > Percentage Of An Array C++ > Tips Or Help C++
Add Reply New Topic New Poll
Page 1 of 1
norwaynoway
#1 Nov 14 2017 01:37pm
Group: Member
Posts: 62
Joined: Feb 23 2017
Gold: 143.00
I have a fixed array of 50 elements which consists of integers the user enters. If it's a partially filled array, it will only show numbers that were entered by the user. What I want to do is only show the highest 70% of those numbers and drop the lowest 30%. Im not exactly sure how to do this with an array. Any tips?

Edit: I'm thinking
1. sort the array in ascending order
2. figure out how much 30% of the number of elements there are
3. Then figure out how to drop them. Not sure how to do this part

This post was edited by norwaynoway on Nov 14 2017 01:44pm
YCX
#2 Nov 14 2017 04:43pm
Group: Member
Posts: 86
Joined: Jan 24 2009
Gold: 908.85
Instead of dropping the first 30%, how about showing only the integers after that, up to the end of the entered integers?

e.g. User enters 1, 2, 3, 8, 7, 6, 5, 4, 9, 0
Sort: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...]
Display, starting at index 3 up to index 9: 3, 4, 5, 6, 7, 8, 9
spaceleak
#3 Nov 14 2017 06:22pm
Group: Member
Posts: 1,603
Joined: Sep 28 2014
Gold: 29,225.00
Are you using a raw array? Do you have to? A STL container would be more suitable.

You can't dynamically resize an existing raw array in C++, so if you have to use a raw array you will pretty much have to do what YCX suggests and display a range of indexes or copy that range of indexes to a new array to simulate "dropping".

This post was edited by spaceleak on Nov 14 2017 06:28pm
norwaynoway
#4 Nov 14 2017 08:52pm
Group: Member
Posts: 62
Joined: Feb 23 2017
Gold: 143.00
Quote (YCX @ Nov 14 2017 02:43pm)
Instead of dropping the first 30%, how about showing only the integers after that, up to the end of the entered integers?

e.g. User enters 1, 2, 3, 8, 7, 6, 5, 4, 9, 0
Sort: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...]
Display, starting at index 3 up to index 9: 3, 4, 5, 6, 7, 8, 9


Ah well the array is limited to 50 but the user can can choose to input any number of values 1-50 if they choose. So I Wouldnt be able to just not display the first 15.
But one other issue is that these integers that the user enters are calculated after I sort out the bottom 30%. They are grades for quizzes. So after I sort this array I have to use it to calculate the gpa for the top 70%. If I choose it to display these then they would still be calculated in the gpa since they still exist in the array.


Quote (spaceleak @ Nov 14 2017 04:22pm)
Are you using a raw array? Do you have to? A STL container would be more suitable.

You can't dynamically resize an existing raw array in C++, so if you have to use a raw array you will pretty much have to do what YCX suggests and display a range of indexes or copy that range of indexes to a new array to simulate "dropping".


Yeah it has to be that type of an array. Ok copying The range to a new array is a good idea.

Thanks for the ideas I'm going to mess around with both
norwaynoway
#5 Nov 15 2017 04:38pm
Group: Member
Posts: 62
Joined: Feb 23 2017
Gold: 143.00
Quote (spaceleak @ Nov 14 2017 04:22pm)
Are you using a raw array? Do you have to? A STL container would be more suitable.

You can't dynamically resize an existing raw array in C++, so if you have to use a raw array you will pretty much have to do what YCX suggests and display a range of indexes or copy that range of indexes to a new array to simulate "dropping".


Copying the range to a new array worked out well. I'm not sure why that option never came to mind. Thank you for your suggestion! I don't have too much fg but will shoot u some for the help. :thumbsup:
Go Back To C/C++/C# Topic List
Page 1 of 1