Thread: Program that accepts an array of integers and prints the minimum of the numbers

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    36

    Program that accepts an array of integers and prints the minimum of the numbers

    My boss asked me to write

    a program that accepts an array of integers and prints the minimum of the numbers

    What does he mean by that ??

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You'd probably have to ask him or her to be sure.

    Normally that would mean reading integers from a file or standard input and then outputting to a file or standard output the smallest number you read in.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Smaller number means ..

    if its 12312901279323

    Then print "0" ?




    Quote Originally Posted by Daved View Post
    You'd probably have to ask him or her to be sure.

    Normally that would mean reading integers from a file or standard input and then outputting to a file or standard output the smallest number you read in.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by kolucoms6 View Post
    Smaller number means ..

    if its 12312901279323

    Then print "0" ?
    You don't have a 0, you have a 12312901279323. If you had
    12312901279323
    853576
    124
    0

    then yes, the smallest number there is 0.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Can you help me with the Code please ?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by kolucoms6 View Post
    Can you help me with the Code please ?
    You seem to have written your code in invisible ink.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    :-) Invisible ?

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    We generally help with existing code. You try and if you have a specific question you ask. It's hard to help with the code when there is no code to help with.

    When you have code to show, make sure to post it in [code][/code] tags.

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Code:
    #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 << "A - Find the largest # with a known quantity of numbers\n";
            cout << "B - Find the smallest # with an unknown quantity of numbers\n";
            cout << "C - Quit\n";
            cout << "Please enter your choice: ";
        cin >> MenuChoice;
        return MenuChoice;
    }
    
    void find_largest()
    {
        int largest = 0;
        int numbers=0, input, i=0;
    
        cout << endl;
        cout << "How many numbers to enter: ";
        cin >> numbers;
    
        for (i=0; i<numbers; i++)
        {
            cout << "Enter number " << i+1 << ": ";
            cin >> input;
            if (input > largest)
                largest = input;
        }
    
        cout << endl;
        cout << "Largest: " << largest << "\n\n";
    }
    
    void find_smallest()
    {
        int smallest = 9999;
        int input=0, i=1;
        cout << endl;
    
        do
        {
            cout << "Enter number " << i << ": ";
            cin >> input;
            i++;
            if ((input < smallest) && (input != -99))
                smallest = input;
        } while (input != -99);
    
        cout << endl;
        cout << "Smallest: " << smallest << "\n\n";
    }

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That's nice code that you apparently found on the internet: http://www.dreamincode.net/forums/showtopic20751.htm

    But if you aren't going to do any work yourself it makes no sense for us to do it for you.

  11. #11
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Now, as I have Code, I can study it and learn from it...

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I encourage you to do so. I just wanted others to be aware, in case it wasn't obvious, that your posted code wasn't something you came up with and needed help with.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Your boss asked you to write this eh? Seems very simplistic for 'work stuff'.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. Problem with Dynamically Increasing Array of Integers
    By laserlight in forum C++ Programming
    Replies: 30
    Last Post: 07-04-2008, 07:27 AM
  3. Replies: 13
    Last Post: 01-13-2008, 09:38 PM
  4. Program that prints numbers in columns
    By rayrayj52 in forum C++ Programming
    Replies: 12
    Last Post: 09-20-2004, 02:43 PM
  5. How to complete program. Any probs now?
    By stehigs321 in forum C Programming
    Replies: 7
    Last Post: 11-19-2003, 04:03 PM