I need some help!! PLEASE!!

This is a discussion on I need some help!! PLEASE!! within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I tried asking this on the c++ board but no luck. here is my problem. I have a program that ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    19

    I need some help!! PLEASE!!

    I tried asking this on the c++ board but no luck.

    here is my problem. I have a program that ask a user to enter some numbers it then will spit out the max and min and number of numbers he entered.

    After that it will ask them if they would like to run the program again. If they choose yes how do I clear out the numbers the entered before.

    ex: First run

    Numbers Entered: 1, 2, -1, 9
    -You entered 4 numbers
    - Largest is 9
    - Smallest is -1

    Second Run:

    Numbers Entered: 6, -8, 3, 5
    - You entered 8 numbers //Should say 4
    - Largest is 9 //Should say 6
    - Smallest is -8 //This is right.


    This is only my second program I have written so I am still a novice at this and can not figure out what to do. What is the code and where do I put it in this program?


    /* Name: Nicholas Dillon Febuary 21, 2002
    *
    *
    * Assign2.cpp
    *
    * This program finds the max and the min out of a group of numbers.
    *
    *
    * input:
    *
    * numbers
    *
    * ouput:
    *
    * max - largest number entered
    * min - smallest number entered
    *
    *
    */

    #include <iostream.h>


    int main()
    {
    const int MAX = 50; //Max size of array
    int count = 0; //Counts # of items entered
    int index = 0; //loop variable
    int numbers_array[MAX]; //Array to store numbers
    char ch = 'Y'; //Run again variable
    int max; //Maximum Variable
    int min; //Minimum Variable
    int i = 0; //variable


    do
    {
    while(ch == 'Y' || ch == 'y')
    {

    cout << "Please enter a number: "; endl;
    cin >> numbers_array[index];
    index++;
    count++;
    cout << "Please enter a number: "; endl;
    cin >> numbers_array[index];
    index++;
    count++;
    endl;
    cout << "Do you want to enter another number?(Y/N) ";
    cin >> ch;
    }

    min = numbers_array[0];
    max = numbers_array[0];

    while (i < count)
    {
    if (numbers_array[i] < min)
    {
    min = numbers_array[i];
    }
    else if(numbers_array[i] > max)
    {
    max = numbers_array[i];
    }

    i++;
    }

    cout << "You entered a total of " << count;
    cout << " numbers." <<endl;
    cout << "The largest number you entered was " << max << endl;
    cout << "The smallest number you entered was " << min << endl;
    cout << "Would you like to run program again?(Y/N)";
    cin >> ch;
    }
    while (ch == 'Y' || ch == 'y');

    return 0;
    }


    Thanks for the help! I dont knwo what the he!!to do!

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Oh! The answers so clear! Stop being so damned impatient, and don't Cross-post.

  3. #3
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    not sure if this has been answered or not... and I'm not sure about how to do it in C++, but why not just reinitialize your array?

    I think your problem is that you're not resetting your counters when running the request for numbers again... hence, you're just adding array elements...

    you might just want to run through a loop in your array setting everything back to zero.. !? But I wouldn't recommend that method..

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    If it's not answered on the C++ board, it's sure as hell not gonna get answered here.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21