I'm having troubles with a cin statement in my code and need some guidance. I need my code to refresh an array with completely different ASCII characters, then have the user enter a keystroke and have the refresh speed increase by a few hundred miliseconds every time. Now my C++ teacher gave me a code to use (using the windows.h library) but i have no idea how to apply it or if theres an easier way.

void SetCoord(int x, int y)
{
    COORD thing = (x,y);
    SetConsoleCursorPosition (GetStdHandle ( STD_OUTPUT_HANDLE), thing);
}

that's the code he gave me but i don't know how to apply it to my code. (will post below)
any help would be great! if you have any other questions let me know! this is only the portion of the game that this involves.

void func2()
{
    system("cls");
            cout << "----------------------------------------------------------------------------" << endl;
            cout << "|  You have chosen the Moving Menace game.                                 |" << endl;
            cout << "|  You will be looking for a specific character in this game.              |" << endl;
            cout << "|  When you see the character, enter the key 'G'.                          |" << endl;
            cout << "|  Just as a warning the more you find the character, the faster it moves. |" << endl;
            cout << "|  Are you ready?                                                          |" << endl;
            cout << "----------------------------------------------------------------------------" << endl;
            Sleep(10000);
            //It's over 9000!
            cout << "3" << endl;
            Sleep(1000);
            cout << "2" << endl;;
            Sleep(1000);
            cout << "1" << endl;
            Sleep(1000);
            system("cls");
            cout << "GO!";
            Sleep(1000);
            system("cls");

             // initialize the array
            while(1)
            {

                cout << "Look for this character: '*' \n" << endl;
                char cTest;
                iSize = 16;
                for (int x = 0; x < iSize; x++)
                {
                    for (int y = 0; y < iSize; y++)
                    {
                        cTest = char(rand() % 223 + 33);
                        cArray[x][y] = cTest;
                    }
                }

                // display everything in array
                for (int x = 0; x < iSize; x++)
                {
                    for (int y = 0; y < iSize; y++)
                    {
                        cTest = cArray[x][y];
                        cout<< cTest;
                    }
                    cout << endl;
                }
/*my problems start here! well maybe earlier...*/
                Sleep(1500);
                system("cls");

            }


}

that's the code he gave me but i don't know how to apply it to my code. (will post below)

So what's that code do? That the first thing to understand if you want to use it.

So what's that code do? That the first thing to understand if you want to use it.

its supposed to display a array (16x16) that has every spot occupied by a random ASCII character and at first every 1.5 seconds the array refreshes itself and all the characters are in a completely different spot. now the user is supposed to be looking for a specific character (for testing purposes '*') and when they see that character they enter a keystroke and the array will start refreshing faster. what i'm having problems with is that keystroke function. if any of that made sense...

That's what the code does that your teacher gave you? It doesn't look big enough.

the very first 5 lines of code i posted on here (starting with viod SetCoord..) is what he gave me. the rest is MY code that i have written. its a smaller portion of code from a large assignment i'm doing. the code above is all contained with itself. if that makes sense. i can post the entire code but it seems to me that it would be irrelevent(i know i can't spell)

That's what the code does that your teacher gave you? It doesn't look big enough.

excuse me i didn't understand what you had said. no what my teacher gave me he said its supposed to help with my cin statement.

excuse me i didn't understand what you had said. no what my teacher gave me he said its supposed to help with my cin statement.

OK, continue with the pulling of teeth:

So what's that code do? That's the first thing to understand if you want to use it.

Look at the code. Look up the parts you don't already know. You need to understand the code he gave you. Use your book and GOOGLE.

i do know it's supposed to print each line of my array simoltaneously which leaves my cin statement free from cls functons but i don't know how to apply what he gave me to my code. i understand what he gave me, i just don't how to apply it or if there might be an easier way.

i do know it's supposed to print each line of my array...

No it doesn't.

i understand what he gave me...

No you don't.

Look at it again.

my teacher just explained it to me again but in more detail this time which helped alot and now i understand what that does. but i still don't know how to get the code too do 2 things at once which is what i need help with..

Code cannot do 2 things at once. I can only do one thing then the other. If you would stop being cryptic and give us the necessary details to understand your specific question, we would probably be able to help.

But this "I know what I'm doing but it doesn't work" gives us nothing to go on.

the code is supposed is supposed to display an 2-d array (16x16) of completely different ASCII characters and to start refresh and reposition all of the ASCII characters randomly every 1500 miliseconds. the user is supposed to be looking for a specific character and when they see it they are supposed to enter the keystroke 'G'. when they do this the array will start refreshing faster. where i am stuck is getting the input from the user so the refresh on the array speeds up.
me and my teacher talked everything over and we figured out how to get it to run the 2 processes at once but i need to know how to write a code to check the cin buffer. anyone know how to do this??
we were talking about making it so that it keeps checking the cin buffer for input and at the end of it's current sleep period if there in no inout it will refresh. if there is input it will speed up the refresh. does this make sense?

Now you're making sense. This is only possible with certain compilers because asynchronous input is not part of the C++ Standard. What'cha usin'?

Uh, I think I know what you're doing. Assuming what you want is actually to replace the characters every cycle, then I believe I can help you. Make sure that you have the rand() headers. In your main() function, have the code..

int main()
{
  srand(time(NULL));

  return 0;
}

Make sure this is not in any loop, or the "random" won't change. Also, don't declare any variables in a loop that you are "randoming". This has helped me when I've tried to do similar things.

Hope this helped,

- TZ

You said that your teacher gave you code that contains the line:

COORD thing = (x, y);

Either you are mistaken or you should get another teacher. Because this line of code has the same effect as writing

COORD thing = y;

but the form in which it is written suggests that whoever wrote it thought it would do something different--otherwise, why write it that way?

I am guessing that your teacher actually wrote either

COORD thing(x, y);

or

COORD thing = {x, y};

but either way, something is definitely not right about the version you posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.