CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Help!

  1. #1
    Join Date
    Feb 2003
    Location
    US
    Posts
    2

    Exclamation 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.

  2. #2
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    you best bet is to use std::list because it provides a sort method (to find the smallest/largest).

  3. #3
    Join Date
    Feb 2003
    Location
    US
    Posts
    2
    Im sorry, im not sure what that is.

    Could you provide some coding?

  4. #4
    Join Date
    Apr 2002
    Location
    Australia
    Posts
    54
    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

  5. #5
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    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
  •  





Click Here to Expand Forum to Full Width

Featured