CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Posts
    1

    A bit of help with a code...

    Hello,

    I am creating a program for a class in which we have to create a menu in which allows the function for option A to have the quantity of numbers passed in as a parameter and needs to return the largest number. The function for B should have no parameters and return the smallest number.

    I have created this so far and it works, but I'm not sure that this is what he is asking for:




    #include <iostream>

    using namespace std;

    char DoMenu();
    void find_largest();
    void find_smallest();

    int main()
    {
    char choice;

    do
    {
    choice = DoMenu();

    switch (choice)
    {
    case 'a': // fall through
    case 'A': find_largest(); break;
    case 'b':
    case 'B': find_smallest(); break;
    }

    } while ((choice != 'C') && (choice != 'c'));

    return 0;
    }

    char DoMenu()
    {
    char MenuChoice;
    cout << " ****************************************************************** " << endl;
    cout << endl;
    cout << " A - Find the largest # with a known quantity of numbers. " << endl;
    cout << " B - Find the smallest # with an unknown quantity of numbers. " << endl;
    cout << " C - Quit " << endl;
    cout << endl;
    cout << " ****************************************************************** " << endl;
    cout << endl;
    cout << endl;
    cout < " Please enter your choice: ";
    cin >> MenuChoice;
    cout << endl;
    cout << endl;
    cout << " Excellent! You chose option " << MenuChoice << "! Let's continue." << endl;
    return MenuChoice;
    }

    void find_largest()
    {
    int largest = 0;
    int numbers=0, input, i=0;

    cout << endl;
    cout << " How many numbers would you like to enter?" << endl;
    cin >> numbers;

    for (i=0; i<numbers; i++)
    {
    cout << " Please enter number " << i+1 << ": ";
    cin >> input;
    if (input > largest)
    largest = input;
    }

    cout << endl;
    cout << " The largest number that is in the list you created is " << largest << " " << endl;
    cout << endl;
    cout << " ****************************************************************** " << endl;
    cout << endl;
    }
    void find_smallest()
    {
    int smallest = 9999;
    int input=0, i=1;
    cout << endl;
    cout << " Please enter a list of numbers. When you are finished, enter '-9999' to finish listing." << endl;
    do
    {

    cout << " Enter number " << i << " please : ";
    cin >> input;
    i++;
    if ((input < smallest) && (input != -9999))
    smallest = input;
    } while (input != -9999);

    cout << endl;
    cout << " The smallest number you input was " << smallest << " " << endl;
    cout << endl;
    cout << " ****************************************************************** " << endl;
    cout << endl;
    }



    Any help would be greatly appreciated!

  2. #2
    Join Date
    Oct 2004
    Posts
    296

    Re: A bit of help with a code...

    1) Your first task is to read 5 other threads in this forum. Notice the difference between the code you posted and the code in the other threads.

    2) Then you need to search google and figure out how to post code like they did in the other threads.

    3) Then you need to edit your post and make the necessary changes.
    Last edited by 7stud; April 27th, 2008 at 03:09 PM.

  3. #3
    Join Date
    Mar 2007
    Location
    Montreal, Quebec, Canada
    Posts
    185

    Re: A bit of help with a code...

    What 7stud is trying to say is "use code tags", like this:
    [code]
    here is some code, I used a
    Code:
     tag for it

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