User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,666 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,641 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 3601 | Replies: 6 | Solved
Reply
Join Date: Oct 2004
Posts: 9
Reputation: KittyGirl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
KittyGirl KittyGirl is offline Offline
Newbie Poster

Need some help with min/max in arrays

  #1  
Nov 27th, 2004
I have to write a program for homework that asks for contestant scores, then outputs the total after the lowest and highest number are deleted. This is what I have so far. I can't use a sort since we haven't covered that yet and I'm not sure exactly how to subtract the lowest and highest number without sorting. Any help is much appreciated.

Thanks!

#include <iostream>
using namespace std;

int main()
{
	int counter;
	double sum;
	double data [8];

	cout<<"Enter data: ";
	
	for (counter = 0; counter < 8; counter++)
		data[counter] = 0.0;
	for (counter = 0; counter < 8; counter++)
		cin>>data[counter];
	sum = 0;
	for (counter = 0; counter < 8; counter++)
		sum = sum + data[counter];
	cout<<endl;

	
	cout<<"Total points =  "<<sum<<endl;

	return 0;
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Posts: 12
Reputation: khkwa is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
khkwa khkwa is offline Offline
Newbie Poster

Re: Need some help with min/max in arrays

  #2  
Nov 28th, 2004
I think you can do the following:

Define MAX as the maximum of the scores. First set it as equal to the first element of the array of scores. Then compare successively MAX with the elements of the array. Set MAX as equal to the particular element if MAX is less than the element; otherwise, proceed to compare MAX with the next element.

The minimum MIN of the scores can likewise be obtained.

Finally, of course, just substract MAX and MIN from the sum.
Reply With Quote  
Join Date: Oct 2004
Posts: 9
Reputation: KittyGirl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
KittyGirl KittyGirl is offline Offline
Newbie Poster

Re: Need some help with min/max in arrays

  #3  
Nov 28th, 2004
Is this what you mean?

while (max > 0.0 || max <= 10.0)
Reply With Quote  
Join Date: Nov 2004
Posts: 12
Reputation: khkwa is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
khkwa khkwa is offline Offline
Newbie Poster

Re: Need some help with min/max in arrays

  #4  
Nov 28th, 2004
No, I mean insert the following code into yours after the data are entered:

MAX = MIN = data[0];
for (counter = 1; counter < 8; counter++)
{
if (data[counter]>MAX) MAX = data[counter];
if (data[counter]<MIN) MIN = data[counter];
}



Originally Posted by KittyGirl
Is this what you mean?

while (max > 0.0 || max <= 10.0)
Reply With Quote  
Join Date: Oct 2004
Posts: 9
Reputation: KittyGirl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
KittyGirl KittyGirl is offline Offline
Newbie Poster

Re: Need some help with min/max in arrays

  #5  
Nov 30th, 2004
Thank you so much! This worked beautifully.

I'm fairly new to this stuff, so I usually ask a lot of questions if I'm not quite sure about something.
Reply With Quote  
Join Date: Jan 2006
Posts: 13
Reputation: sosy2001 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
sosy2001 sosy2001 is offline Offline
Newbie Poster

Re: Need some help with min/max in arrays

  #6  
Feb 2nd, 2006
Hello Kitty,

can you help with with my array question? I need to store the users input into an array, then sum the numbers and then print them out in reverse.
Reply With Quote  
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,480
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Rep Power: 8
Solved Threads: 98
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need some help with min/max in arrays

  #7  
Feb 2nd, 2006
Originally Posted by sosy2001
Hello Kitty,

can you help with with my array question? I need to store the users input into an array, then sum the numbers and then print them out in reverse.
Judging by the date this thread was initiated, my guess is that KittyGirl became a KittyWoman, met a CatMan, GotMarried, had maybe a couple of KittyKids and is long gone by now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 7:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC