This code assignment is due by class #14, Wednesday 10/20/2004.

Write a program that reads in any 25 decimal numbers from standart input
source (terminal), determins the actual and absolute lowest & largest
values, and computes average of all the given numbers. You may use
any/all programming techniques we have learned in class, and only those
(no arrays, no recursion, no ADTs).

Sample run:
---------------------------------------------------------
Please input 25 decimal numbers for processing:

5 d 6 7.4 8.23 0.216 -45.7 3 56 124 532 5.237 67.3 45.2 56.9
34.3 361.238 02 -34.2 348.2 32.45 0.33 1.56 7.45 -3.276

Processing...

Actual Min: - 045.70
Actual Max: + 361.24

Absolute Min: + 000.22
Absolute Max: + 361.24

Absolute Total: 1887.187
Average: 75.487

----------------------------------------------------------

Note:
if sample output inside the message is not formated, look for formated
example in attached file - sample_output.txt

All output must be strictly formated:
- decimal points are aligned
- all min/max numbers are printed with precision of 2 decimal places
- total & average are printer with precision of 3 decimal places
- all min/max values have their signs printed, also with strict
formating (one column)
- always use absolute value to compute average

Tips:
1. Do not write your own functions to handle input of all the special
cases, e.x. negative numbers, decimal, etc.
C++ library for cout/cin functions perform all that processing for you

2. you will have to write your own routeen to compute average
3. for that you will have to keep track of all the required
information, ex.
- real min/max
- absolute min/max
- absolute sum

4. you don't need to keep count how many numbers you totaled for
average computation - it is given to you in the problem statment - 25.
5. You must use some sort of a loop to read in all 25 numbers and
perform processing on each input as it comes in.
6. Do NOT write your own function to determine absolute value - use one
already provided to you in math library.

The problem is I can not use "Array". and i dont know how can i declare 25 numbers?? thts why im confuse

## All 17 Replies

3. for that you will have to keep track of all the required
information, ex.
- real min/max
- absolute min/max
- absolute sum

The problem is I can not use "Array". and i dont know how can i declare 25 numbers?? thts why im confuse

Input your values to a single variable in a loop. After the value is read, adjust your current min/max, etc. as necessary.

Wow! Class # 14 already! Fantastic! How time flies. . .

Good luck on this assignment! If you have some code snippets you need help on, feel free to post them and we can try to help.

Not using arrays just means, I think, that you keep running totals on the input:

get a value
add it to the sum, see if it is the min or max, save if so
go on to get next value

so you don't need all 25 values before you can start doing your min/max/avg calculations.

Thanks, Dave and Chainsaw. appreciate it

but lil more help would be appreciated. anyone can post one example how to write this program. havent took C+ in high school, so im not really into it.... and also not a computer major either...jus takking it coz its requirement.

No, quid pro quo. You show us effort, we show you your mistakes.

You need some variables and you need a loop. There's a start.

ok...

#include <iostream>
#include <cmath>
int i;

float input, curr_min, curr_max, curr_abs_min,
curr_abs_max, curr_total;
input=5 ,6, 7.4, 8.23, 0.216, -45.7, 3, 56, 124, 532, 5.237, 67.3, 45.2, 56.9, 34.3, 361.238, 02, -34.2, 348.2, 32.45, 0.33, 1.56, 7.45, -3.276;

for(i=0; i>input;

if(input < curr_min)
curr_min = input;

total += input;
}

// after for loop is over
average = total / 25;

You need the main() function somewhere.

``input=5 ,6, 7.4, 8.23, 0.216, -45.7, 3, 56, 124, 532, 5.237, 67.3, 45.2, 56.9, 34.3, 361.238, 02, -34.2, 348.2, 32.45, 0.33, 1.56, 7.45, -3.276;``

No.

C++ library for cout/cin functions perform all that processing for you

Obtain the value for 'input' using cin many times in a loop. After each value of 'input' is entered in the loop, adjust your min/max/sum/etc.

You'll want to add the following after your #includes to make life easier.

``using namespace std;``

[My god, can I not do this well?]

``for(i=0; i>input;``

This is not the proper syntax for a for loop. And for 25 values, it's likely you want this:

``for ( i = 0; i < 25; ++i )``

#include <iostream>
#include <cmath>
using namespace std;
int main ( )
{

int i;
float input, curr_min, curr_max, curr_abs_min,
curr_abs_max, total, average;

input=5 ,6, 7.4, 8.23, 0.216, -45.7, 3, 56, 124, 532, 5.237, 67.3, 45.2, 56.9, 34.3, 361.238, 02, -34.2, 348.2, 32.45, 0.33, 1.56, 7.45, -3.276;

for(i=0; i < 25; i++)

// compare to see if input < curr_min
if(input < curr_min)
curr_min = input;

if(input < curr_max)
curr_max = input;

if(input < curr_abs_min)
curr_abs_min = input;

if(input < curr_abs_max)
curr_abs_max = input;
// compare for max similar to above
// compare for abs min as above
// compare for abs max as above
total += input;
}

// after for loop is over
average = total / 25;
}

Stupid question:

what can i use to declare the numbers???

``````input=5 ,6, 7.4, 8.23, 0.216, -45.7, 3, 56, 124, 532, 5.237, 67.3, 45.2, 56.9, 34.3, 361.238, 02, -34.2, 348.2, 32.45, 0.33, 1.56, 7.45, -3.276;
``````

Again, no.

Look, it's late and this is not complete. But experiment with it a bit.

`````` #include <iostream>
using namespace std;

int main()
{
float input, minimum, maximum, average, total = 0;
int i;
for ( i = 0; i < 25; ++i )
{
cout << "Enter values #" << i + 1 << ": ";
cin  >> input;
if ( i == 0 )
{
minimum = maximum = input;
}
if ( input < minimum )
{
minimum = input;
}
if ( input > maximum )
{
maximum = input;
}
total += input;
}
average = total / 25;
cout << "minimum = " << minimum << endl;
cout << "maximum = " << maximum << endl;
cout << "average = " << average << endl;
cout << "total   = " << total   << endl;
return 0;
}

/* my output
Enter values #1: 5
Enter values #2: 6
Enter values #3: 7.4
Enter values #4: 8.23
Enter values #5: 0.216
Enter values #6: -45.7
Enter values #7: 3
Enter values #8: 56
Enter values #9: 124
Enter values #10: 532
Enter values #11: 5.237
Enter values #12: 67.3
Enter values #13: 45.2
Enter values #14: 56.9
Enter values #15: 34.3
Enter values #16: 361.238
Enter values #17: 02
Enter values #18: -34.2
Enter values #19: 348.2
Enter values #20: 32.45
Enter values #21: 0.33
Enter values #22: 1.56
Enter values #23: 7.45
Enter values #24: -3.276
Enter values #25: 0
minimum = -45.7
maximum = 532
average = 64.8334
total   = 1620.83
*/
``````

And read up on code blocks.

Thank you very much Dave, Greately appreciated!

ok...here i came up with....
program compile and everything but i think there is something missing/wrong....

when i enter values, i have to put something after i put my one value. meaning...if i put

``````Enter values #1: 5 (press enter)
0 (press enter)
Enter values#2:6 (press enter)
0
``````

then i have to put something after i put 5 (shown above), and next Value#2 comes.....

here is my program and output

``````#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
float input, minimum, maximum,absolute_minimum, absolute_maximum, average,average_absolute, average_total, total, absolute_in\
put ,absolute_total = 0;
int i;
for ( i = 0; i < 25; ++i )
{
cout << "Enter values #" << i + 1 << ": ";
cin  >> input;
cin >> absolute_input;
if ( i == 0 )
{
minimum = maximum = absolute_minimum = absolute_maximum = input;
}
if ( input < minimum, input <absolute_minimum )
{
minimum = input, absolute_minimum = input;
}
if ( input > maximum, input >absolute_maximum )
{
maximum = input, absolute_maximum = input;
}
total += input;
absolute_total  += absolute_input;
}
average = total / 25;
average_absolute = average_total/25;
cout << "minimum = " << minimum << endl;
cout << "maximum = " << maximum << endl;
cout << "average = " << average << endl;
cout << "total   = " << total   << endl;
cout << "absolute_minimum = "<< absolute_minimum << endl;
cout << "absolute_maximum ="<< absolute_maximum <<endl;
return 0;
}
``````

OUTPUT

``````Enter values #1: 5
0
Enter values #2: 0
0
Enter values #3: 6
0
Enter values #4: 7.4
0
Enter values #5: 8.23
0
Enter values #6: 3
0
Enter values #7: 56
0
Enter values #8: 124
0
Enter values #9: 532
0
Enter values #10: 5.237
0
Enter values #11: 67.3
0
Enter values #12: 45.2
0
Enter values #13: 56.9
0
Enter values #14: 34.3
0
Enter values #15: 361.238
0
Enter values #16: 2
0
Enter values #17: -34.2
0
Enter values #18: 348.2
0
Enter values #19: 32.45
0
Enter values #20: 0.33
0
Enter values #21: 1.56
0
Enter values #22: 7.45
0
Enter values #23: -3.276
0
Enter values #24: 7
0
Enter values #25: 3
0
minimum = -45.7
maximum = 532
average = 64.9934
total   = 1624.83
absolute_minimum = -45.7
absolute_maximum =532
``````

HELP WOULD GREATELY APPRECIATED!

Added code tags to quote.

ok...here i came up with....
program compile and everything but i think there is something missing/wrong....

when i enter values, i have to put something after i put my one value. meaning...if i put

Enter values #1: 5 (press enter)
0 (press enter)
Enter values#2:6 (press enter)
0
........

then i have to put something after i put 5 (shown above), and next Value#2 comes.....

here is my program and output

``````#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
float input, minimum, maximum,absolute_minimum, absolute_maximum, average,average_absolute, average_total, total, absolute_in\
put ,absolute_total = 0;
int i;
for ( i = 0; i < 25; ++i )
{
cout << "Enter values #" << i + 1 << ": ";
cin  >> input;
cin >> absolute_input;
if ( i == 0 )
{
minimum = maximum = absolute_minimum = absolute_maximum = input;
}
if ( input < minimum, input <absolute_minimum )
{
minimum = input, absolute_minimum = input;
}
if ( input > maximum, input >absolute_maximum )
{
maximum = input, absolute_maximum = input;
}
total += input;
absolute_total  += absolute_input;
}
average = total / 25;
average_absolute = average_total/25;
cout << "minimum = " << minimum << endl;
cout << "maximum = " << maximum << endl;
cout << "average = " << average << endl;
cout << "total   = " << total   << endl;
cout << "absolute_minimum = "<< absolute_minimum << endl;
cout << "absolute_maximum ="<< absolute_maximum <<endl;
return 0;
}
[b]OUTPUT[/b]

Enter values #1: 5
0
Enter values #2: 0
0
Enter values #3: 6
0
Enter values #4: 7.4
0
Enter values #5: 8.23
0
Enter values #6: 3
0
Enter values #7: 56
0
Enter values #8: 124
0
Enter values #9: 532
0
Enter values #10: 5.237
0
Enter values #11: 67.3
0
Enter values #12: 45.2
0
Enter values #13: 56.9
0
Enter values #14: 34.3
0
Enter values #15: 361.238
0
Enter values #16: 2
0
Enter values #17: -34.2
0
Enter values #18: 348.2
0
Enter values #19: 32.45
0
Enter values #20: 0.33
0
Enter values #21: 1.56
0
Enter values #22: 7.45
0
Enter values #23: -3.276
0
Enter values #24: 7
0
Enter values #25: 3
0
minimum = -45.7
maximum = 532
average = 64.9934
total   = 1624.83
absolute_minimum = -45.7
absolute_maximum =532``````

HELP WOULD GREATELY APPRECIATED!

Yup. It does just what you tell it to do -- wait for two numbers, input and absolute_input.

ohh yeahhh, damn it, this is stupid mistake....

thanks man. ur the man!!!

now all i gotta do is arrange the numbers in row. but jus wondering, i didnt even used "endl", so why isnt it coming out in row?

now all i gotta do is arrange the numbers in row. but jus wondering, i didnt even used "endl", so why isnt it coming out in row?

You didn't?

cout << "minimum = " << minimum << endl;
cout << "maximum = " << maximum << endl;
cout << "average = " << average << endl;
cout << "total = " << total << endl;
cout << "absolute_minimum = "<< absolute_minimum << endl;
cout << "absolute_maximum ="<< absolute_maximum <<endl;
return 0;
}

uummm...yeaaaaaa, ur right. but actualy i was looking at something else....mah bad

now all i gotta do is arrange the numbers in row

i meant..numbers in one line....

"Please input 25 decimal numbers for processing:

5 d 6 7.4 8.23 0.216 -45.7 3 56 124 532 5.237 67.3 45.2 56.9
34.3 361.238 02 -34.2 348.2 32.45 0.33 1.56 7.45 -3.276"

It can handle that as is (well, except for the d). It'll just mess with the prompting. This has only a couple of slight changes.

``````#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
float input, absolute_input, minimum, maximum, average, total = 0,
absolute_minimum, absolute_maximum,
average_absolute, average_total = 0, absolute_total = 0;
int i;
for ( i = 0; i < 25; ++i )
{
cout << "Enter values #" << i + 1 << ": ";
cin  >> input;
cin >> absolute_input;
if ( i == 0 )
{
minimum = maximum = absolute_minimum = absolute_maximum = input;
}
if ( input < minimum, input <absolute_minimum )
{
minimum = input, absolute_minimum = input;
}
if ( input > maximum, input >absolute_maximum )
{
maximum = input, absolute_maximum = input;
}
total += input;
absolute_total  += absolute_input;
}
average = total / 25;
average_absolute = average_total/25;
cout << endl;
cout << "minimum = " << minimum << endl;
cout << "maximum = " << maximum << endl;
cout << "average = " << average << endl;
cout << "total   = " << total   << endl;
cout << "absolute_minimum = "<< absolute_minimum << endl;
cout << "absolute_maximum ="<< absolute_maximum <<endl;
return 0;
}

/* my output
Enter values #1: 5 0 6 7.4 8.23 0.216 -45.7 3 56 124 532 5.237 67.3 45.2 56.9 34.3 361.238 02 -34.2 348.2 32.45 0.33 1.56 7.45 -3.276
Enter values #2: Enter values #3: Enter values #4: Enter values #5: Enter values #6: Enter values #7: Enter values #8: Enter values #9: Enter values #10: Enter values #11: Enter values #12: Enter values #13: 5 0 6 7.4 8.23 0.216 -45.7 3 56 124 532 5.237 67.3 45.2 56.9 34.3 361.238 02 -34.2 348.2 32.45 0.33 1.56 7.45 -3.276
Enter values #14: Enter values #15: Enter values #16: Enter values #17: Enter values #18: Enter values #19: Enter values #20: Enter values #21: Enter values #22: Enter values #23: Enter values #24: Enter values #25:
minimum = -45.7
maximum = 532
average = 64.8334
total   = 1620.84
absolute_minimum = -45.7
absolute_maximum =532
*/``````

yoo it doesnt compile. today is the last to hand it in....please help

how can i create a program that will compute for the net income of an employee if:
Net income=gross income-Deductions
Gross income=Number of days worked * rate_per_day
*rate per day =382
Deductions:
WTax= 15% of the gross income
sss= 100
Phil=100
HMDF=100

thank you please response immediately. :))

commented: Don't bump a 6 year old thread -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.