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

Thread: Help!

  1. #1
    Join Date
    Oct 2009


    I have a problem in c++ where I must be able to enter a maximum of 100 values. I must be able to cancel the input whenever I want. And when the input is finished a menu will show up. I'll be using vectors and loops.

    How do I:
    1. calculate the highest value?
    2. How do I calculate the lowest value?
    3. How do I calculate the mean?
    4. How do I list all of the numbers in one column with one decimal right under each other.

    #include <iostream>
    #include <iomanip>
    #include <stdlib.h>
    using namespace std;
    void main()
    const int value=100;
    double middle, highest, lowest, sum = 0;
    double counter[value + 1];
    int i, val;

    for (i=1; i<=value; i++)

    cout << "Enter some values: ";
    while (cin >> value)
    cin >> counter[i];
    sum+= counter[i];

    middle = sum / value;

    cout << "1. highest" << endl;
    cout << "2. lowest" << endl;
    cout << "3. middle" << endl;
    cout << "4. Lista" << endl;
    cout << "5. end" << endl;
    cout << endl << "Välj: ";
    cin >> option;

    case 1:


    case 2:


    case 3:


    case 4:


    case 5:



    Have I done anything wrong so far?


    Any help appreciated!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Seattle, WA

    Re: Help!

    Well, I don't see any vectors there, just an array.

    You aren't going to have much luck trying to read from cin into a const int (value).

    Why are you ignoring counter[0]?

    What is the condition under which input ends with fewer than 100 numbers?

    main() should return int.

    I don't see a loop to take you back to the menu after executing each option.

    "middle" probably isn't the best variable name for a mean, since it brings to mind a median instead.

    Tasks (1), (2), and (3) are pretty trivial math operations, you should be able to write each in 3-4 lines. If you're allowed to use the STL algorithms, each becomes one line. I'm not sure what you mean by (4).

  3. #3
    Join Date
    Oct 2009

    Re: Help!

    Can you correct it for me?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center