Help with outputting arrays

We were asked to write a program that will stimulate a high low game. User has 10 chances to get the random number between 1 and 100. Guessing it or not, the program will display the guesses the user entered. My output when I do guess the random number right is messed up. Any help will do good! Thank you again!

PLEASE DO NOT PAY ATTENTION TO THE COMMENTS! :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*******************************************************************************
* Program Name:
* Author:           
* Date:
* Course/Section:   CSC-110
*Program Description:
*
*******************************************************************************/

/**************************** Compiler Directives *****************************/

#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;

/************************** Global Data Declarations **************************/

//None in this program.

/**************************** Function Prototypes *****************************/

/*******************************************************************************
* Function Name:    main
* Author:           Chad Martinez
* Function Description:
*
* Pseudocode:
*   Level 0
*   -------                                                     Variables
*
*******************************************************************************/

int main ()
{
    //Local constants
    const int SIZE = 10;        //Sets the size of the array/chances
    const int MIN = 1;       //Change if lower range is needed
    const int MAX = 100;    //Change if higher range is needed

    //Local variables
    int count = 0;                  //Counter for array
    int guess[SIZE];            //Array for having guesses stored into
    int chances = 10;           //Chances user has
    char ans;
    int tries = 0;
    int count2 = 0;
    int random; //Sets random number within range

/******************** Begin main Function Executables *************************/
    do
    {
    //Creates Random number
    srand(time(0));
    random = (rand() % (MAX - MIN) + 1);
    system("cls");

    //Input guesses
    do
    {
        cout << "I have a number between and including 1 and 100. You have " <<
                chances << " to get it." << endl;
        do
        {
            cout << "Guess #" << count + 1 << ": ";
            cin  >> guess[count];
            tries++;

            if ((guess[count] < MIN) || (guess[count] > MAX))
            {
                cout << "Please guess between " << MIN << " & " << MAX << " only."
                << endl;
            }
            else if (guess[count] < random)
            {
            cout << guess[count] << " is low. Go higher." << endl;
            }

            else if (guess[count] > random)
            {
                cout << guess[count] << " is high. Go lower." << endl;
            }

            else if (guess[count] == random)
            {
                system("cls");
                cout << "CONGRATULATIONS! " << random << " was the number"
                << " I had. It took you " << count + 1 << " try/ies." << endl
                << "Here are your guess/es:" << endl;
            }

            count++;

        }while(guess[count] != random);


                for (count2 = 0; count2 <= tries; count2 ++)
                {
                    cout << "Guess #" << count2 + 1 <<": " << guess[count2]
                    << endl;

                }

        //Successful Output
        }while(tries != 10);

        system("cls");
        cout << "Sorry, you did not guess my number. It was " << random << "."
        << endl << "Here were your guesses:" << endl;

        for (count = 0; count <= (tries - 1); count ++)
        {
            cout << "Guess #" << count + 1 << ": " << guess[count] << endl
             << endl;
        }



    //Unsuccessful Output


    cout << "Try again? (Y/N): ";
    cin >> ans;

    }while (ans == 'Y' || ans == 'y');


    //Calculations

    //Clear the screen


    //Display
    //Hold execution on screen
    system("pause");

    //Indicate to OS successful termination of program
    return 0;

   //End main
}
Topic archived. No new replies allowed.