Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,550 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,569 people online right now. Registration is fast and FREE... Join Now!




C++ Parameter quesion

 
Reply to this topicStart new topic

C++ Parameter quesion

Cruch
22 Nov, 2007 - 11:17 PM
Post #1

New D.I.C Head
*

Joined: 15 Nov, 2007
Posts: 2


My Contributions
Here is the code that i have written so far:

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':
            case 'A': find_largest();
                break;
            case 'b':
            case 'B': find_smallest();
                break;
        }

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

    return 0;
}

char DoMenu()
{
    char MenuChoice;

        cout << "\n Menu";

        cout << "\n ================";

        cout << "\n A - Find the largest # with a known quantity of numbers\n";

        cout << "\n B - Find the smallest # with an unknown quantity of numbers\n";

        cout << "\n C - Quit\n";

        cout << "\n Please enter your choice: ";

    cin >> MenuChoice;

    return MenuChoice;
}

void find_largest()
{
    int largest = -9999;

    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 << "The largest number is: " << 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 << "The smallest number is: " << smallest << "\n\n";
}


And I have to do this to it:

The function for A should 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.

Here is some pseudocode for your Greatest function:

CODE
void Greatest()

{

      // Initialize final result variable to largest number possible

      //

      // Ask user How many numbers he would like to enter

      // Read number of numbers user plans to enter

      // start a loop, increment from 0 to number of numbers user plans to enter

      //       Read next number

      //       Compare number to final result variable

      //       if number is less than final result variable, then

      //       store in final result variable

      // end of loop

}


Can anyone help, i am lost.

Thanks

This post has been edited by jjhaag: 23 Nov, 2007 - 01:15 AM
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: C++ Parameter Quesion
23 Nov, 2007 - 01:22 AM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
The code seems to be in working order, simply requiring a few tweaks so that it meets the requirements of the assignment. Is that what you are having trouble with, or is there something about this that I'm just not seeing here? If it's a problem of making those changes, what have you tried?

And please post code using the code tags, like this: code.gif. It makes it way easier to read. I've corrected it in the above post, but you'll need to do it yourself next time.
User is offlineProfile CardPM
+Quote Post

Cruch
RE: C++ Parameter Quesion
25 Nov, 2007 - 08:06 PM
Post #3

New D.I.C Head
*

Joined: 15 Nov, 2007
Posts: 2


My Contributions
QUOTE(jjhaag @ 23 Nov, 2007 - 02:22 AM) *

The code seems to be in working order, simply requiring a few tweaks so that it meets the requirements of the assignment. Is that what you are having trouble with, or is there something about this that I'm just not seeing here? If it's a problem of making those changes, what have you tried?

And please post code using the code tags, like this: code.gif. It makes it way easier to read. I've corrected it in the above post, but you'll need to do it yourself next time.



Yes, I am having trouble knowing what needs to be changed. I am really new to this, I have no idea what I'm doing I have only been learning this for about 6 weeks. I'm really trying to understand it but i have no one to guide me.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month