Thread: What do I need to do?

  1. #1
    Registered User
    Join Date
    Feb 2002

    What do I need to do?

    I have a program that takes numbers entered and tells the user the total number or numbers entered and the max and the min. But then I ask the user if they would like to rerun the program and if they press yes it will run it again, but it does not clear out the index. it just keeps adding to it.

    Exp. you entered 3 numbers the first time...5, 15, -5

    Program will display: You entered 3 numbers.
    The largest number was 15
    The smallest number was -5

    You select to rerun again.

    You enter 3 more numbers......20, -2, 8

    Program will display: You entered (6) numbers.
    The largest number was 20
    The smallest number was (-5)

    errors in ()

    here is the code I have. What do I need to do to reset it back?

    <code>#include <iostream.h>

    int main()
    const int MAX = 50;
    int count = 0;
    int index = 0;
    int numbers_array[MAX];
    char ch = 'Y';
    int max;
    int min;
    int i = 0;

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

    cout << "Please enter a number: ";
    cin >> numbers_array[index];
    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];


    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 << "Do you want to re run this program?(Y/N)";
    cin >> ch;
    while (ch == 'Y' || ch == 'y');

    return 0;

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    cmon use your brain. You obviously know enough about c++ to work this out on your own but i suggest something along the lines of....

    if(we are going again) thiscounter=thatcounter=allothercounters=0;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

Popular pages Recent additions subscribe to a feed