English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm not sure how to go about the following problem:

Write a program that will prompt the user to enter a list of integer numbers that are separated by either a space (whitespace) or a return (\n). Your program should then call three functions called “largest”, “smallest” and “average” that will return the largest, smallest and average number in the list. Main should then report the largest, smallest number as well as the average of all numbers in the list. Test your program on the following input > 3 4 6 7 8 10 12 24 45 67 76 34 23 4.

2007-03-28 12:51:57 · 4 answers · asked by Anonymous in Education & Reference Homework Help

4 answers

1. accept user input
2. using a loop, piece the string by whitespace
3. In the loop, for each number:
a. if the number is bigger than the largest one so far, it's the new largest
b. if the number is smaller than the smallest one so far, it's the new smallest
c. add the number to a running sum so you can average when the loop ends.

Before the loop start your large number count at -MAXINT, and your small count at MAXINT, so that the first number becomes both the largest and smallest by default.

There's really not much more to it, this is a pretty straightforward problem. If you get to 30 lines of code you're not doing something right...

2007-03-28 12:59:31 · answer #1 · answered by doom_burrito 2 · 0 0

matttttttthhhhhhhh, not again, welll all i have to say, is that maybe u should ask a classmate from school, parent,etc.... this way u willl get the answer faster and posssibly more corrrect

2007-03-28 13:20:16 · answer #2 · answered by island girl!! 5 · 0 0

iM USUALLY GOOD iN MATH BUT...WHAT THE HELL WAS THAT?!?!?!

2007-03-28 12:55:23 · answer #3 · answered by Anonymous · 0 0

i don't get it sorry??????????

2007-03-28 12:58:09 · answer #4 · answered by Katie L 3 · 0 0

fedest.com, questions and answers