|
-
February 28th, 2003, 06:28 PM
#1
Help!
I need some help with something. If your not willing to help or you have something negative to say please dont even bother replying.
I am in Computer Programming right now. I am stuck on a problem. Here it is:
Write a program that asks the user for a series of integers one at a time. When the user enters the integer 0, the program displays the following information:
The number of integers in the series (not including zero)
The average of the integers
The largest integer in the series
The smallest integer in the series
The difference between the largest and smallest integer in the series.
If you know how to do this using loops, please reply or email me at [email protected]
Any help is greatly appreciated.
-
February 28th, 2003, 07:45 PM
#2
you best bet is to use std::list because it provides a sort method (to find the smallest/largest).
-
February 28th, 2003, 09:30 PM
#3
Im sorry, im not sure what that is.
Could you provide some coding?
-
February 28th, 2003, 10:17 PM
#4
I have found the best way to find initial help is to use the Search function in this forum. If you are not sure what std::list is - try searching there under Visual C++ or C++ programming. You should get lots of general help and examples. I would suggest this might be your best option if you have no idea where to begin. Do the same thing in MSDN if you have it (or on the MSDN site).
Em
-
March 1st, 2003, 10:11 AM
#5
Code:
std::list<int> mylist;
mylist.push_back( 1 );
mylist.push_back( 4 );
mylist.push_back( 2 );
mylist.push_back( 3 );
mylist.sort( greater<int>() );
int big = mylist.front();
int small = mylist.back();
int ttl = 0;
for( std::list<int>::iterator i = mylist.begin();i != mylist.end();++i )
ttl += *i;
int avg = ttl / mylist.size();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|