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

Username:   Password: 
 RegisterRegister   
 Finding Minimum and Maximum of numbers.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
camilaa




PostPosted: Sat Jan 23, 2010 6:07 pm   Post subject: Finding Minimum and Maximum of numbers.

I have a class project, and I can't figure what commands to use to find the minimum and max of numbers that are entered.

Here is the program description: Create a program that will calculate the average of an unknown number of positive integers. User enters numbers until they ?run out? of numbers (indicated by entering the ?trigger? value of ?1). When the trigger is entered the program will display the total number of integers entered, the smallest and largest number entered, and the average of the entered integers (rounded to 1 decimal place).


The only thing i'm stuck on is the min and max, if you know the command or how to do it, please help me!
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Sat Jan 23, 2010 6:22 pm   Post subject: RE:Finding Minimum and Maximum of numbers.

Have a variable for the min/max and set it to maxint/minint (so that anything is less/more than it), then when you get input compare it to the input. If it is smaller/larger than the min/max, then set the min/max to the input.

Read it twice. Once using the words on the left side of the slash, then once with words on the right side of the slash.

Hope that helps.
Clayton




PostPosted: Sun Jan 24, 2010 3:34 pm   Post subject: RE:Finding Minimum and Maximum of numbers.

1) Put all of the elements in the array
2) Sort the array (preferrably not linearly)
3) Output the first and last elements of said array
4) ???
5) Profit!
sportygal1994




PostPosted: Wed Mar 17, 2010 2:21 pm   Post subject: Re: Finding Minimum and Maximum of numbers.

Like Terrance said, make variables representing the min and max. Also make one called the sum, and one to count how many they entered, im going to use total for the sum and number for the number entered. In a loop get the number, add it to sum, add one (the number 1) to number, then use if statements to compare it to the man and min. If it is lower than min/higher than max then set the min or max to the number entered. Lastly, have an exit when statement saying that when 1 in entered exit the loop. Then make a put statement where it outputs min, max and sum divided by number (might be less one depending on where your exit when statement is). I'd program it here for you, but that would be giving you the answer, and I've given you enough here. Good luck!
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  [ 4 Posts ]
Jump to:   


Style:  
Search: