Stack Exchange
A small part of my code dont work ?? Help me identify what im doing wrong
int main()
{
    //declare variables
    int randomNumber = 0;
    int numberGuess  = 0;
    int attempts     = 0;
    int startTime    = 0;
    int endTime           = 0;
    int totalSecond  = 0;
    int upperBound  =  0;
    char gameType   = ' ';
    char again      = 'Y';

    while(again == 'Y' || again == 'y')
    {
        cout <<" Game Type Enter B for Beginner,I for Intermediate, and A for Advanced:";
        cin >> gameType;
        gameType=toupper(gameType);

        if(gameType == 'B')
        {
            cout <<" Guess a number from 1 through 10:";

            upperBound = 10;

        }
        else if( gameType == 'I')
        {
            cout <<" Guess a number from 1 through 100:";

            upperBound = 100;
        }
        else if( gameType == 'A')
        {
            cout <<" Guess a number from 1 through 1000:";

            upperBound = 1000;
        }
        else 
            cout <<" Invalid Game Level:";
        cout << endl;

        //generate a random number

        srand(static_cast<int>(time(0)));
        randomNumber = 1 + rand() % ((upperBound) - 1 + 1);

        //get first number guess from user
        cin >> numberGuess;
        startTime = static_cast<int>(time(0));
        while ( numberGuess != randomNumber)
        {
            if( numberGuess > randomNumber)
            {
                cout <<"Sorry, guess lower:";
                cin >> numberGuess;
            }
            else if ( numberGuess < randomNumber)
            {
                cout <<"Sorry, guess higher:";
                cin >> numberGuess;
            }
            attempts+=1; 

        }
        cout << endl <<" Yes, the number is " << randomNumber <<"." << endl;
        endTime= static_cast<int>(time(0));
        totalSecond = endTime- startTime;
        cout << endl <<" This is how many attempts you took:" << attempts << endl;
        cout << endl <<" This took :" << totalSecond <<" seconds"<< endl;
        cout <<" Do you want to play again? (Y/N)";
        cin >> again;
        cout << endl << endl;
    } 

    system("pause");
    return 0; 
}

My attempts are adding all up together on each game why is this?? Like if I play one game it displays I took 5 attempts and when I play again say I took 3 attempts it will say I took 8 attempts why??Then it go on and on??

Please, use a more descriptive title and not a general one as your code does not work.

oh ok just new to this

Welcome aboard. Totally understood, these comments are just for letting new users understand how they should use SO. For more help, you could read the FAQ too.

Because you're not resetting attempts to zero between loops. Instead you set it to zero when you declare it (int attempts = 0;) but then keep whizzing around your loop without doing anything to set it back to zero. All your other variables are similarly not reset but most are set in the setup phase of your code.

so I actually got it backwards

You have to reset the number of attempts at the start of the "new game" loop.
 while(again == 'Y' || again == 'y')
   {
    attempts = 0;

Don't implement the complete program functionality in one single giant main() method. Split it into functions like you could have implemented resetGameState() and set attempts and other game state variables back to defaults.
In the long run, it's better to understand how classes and Object-oriented programming works. In OOP, you could have a Game class with attempts etc. encapasulated inside as its member variables and then in your main() you could use it like:
while (again == 'Y' || again == 'y')
{
    Game newGame = new Game(); // with attempts etc. set to defaults automatically
    newGame.start(); // this is Java syntax actually; you may have to
    // do it in a slightly different way in C++ but the concept is same

Here's an excellent article on C++ Objects and Classes to get you started.
