need ppl to solve my prob on the space bar and esc hit.

wad i need help is that if u press space bar it will stop at the line u r printing and repeat it again and again unless u press space bar again to continue from where u stopped. and my esc dosent seem to work... need help urgently thnx...







#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define ESC 27
#define SPACE 32

int main()
{
int numArray[10]={31,32,33,34,35,36,37,38,39,40}; // ten boxes in int array and is named x,....
int index;
int temp;
char keynum;

printf("\tStart/Stop Number Rotation\n");
printf("\t==========================\n");
printf("\n");
printf("\tHit space bar to start number rotation.\n");
printf("\tTo stop number rotation, hit space bar again.\n");
printf("\tpress ESC to quit at anytime.\n");
printf("\n");
printf("\tHit any key to begin.\n");

system("pause");
while (true)
{
if(kbhit())
{
for(index=0 ; index<10 ; index++)
{
printf("%02d ",numArray[index]); //array start from 21-30
_sleep(100);
}

printf("\t\n");

for(index=0 ; index<9 ; index++)
{
temp = numArray[index];
numArray[index] = numArray[index+1];
numArray[index+1] = temp;

}

}
else if(keynum==SPACE)
{

for(index=0 ; index<10 ; index++)
{
printf("%02d ",numArray[index]);
_sleep(100);
}

}
else if(keynum==ESC)
{
break; //break out of loop

}

}

printf("Try again?");
printf("\n");

system("pause");
return 0;
}
http://www.cplusplus.com/forum/articles/1295/

And for the love of God, try to write as if you didn't have brain damage.
????? i didnt know hw to solve tats y i asked...
need help urgent
Please use proper grammar, [code][/code] tags and read the article helios posted as just saying "dosent seem to work..." and posting sourcecode is not a way to get help faster
Firstly wrap your code in [code] and [/code] tags.

Secondly, you notice how we all write "you" as "you" and not "u"? It's two letters, it really doesn't make a difference to how long it takes you to type. It shows a little effort and willingness to learn.

Also if you use proper grammar when writing plaintext it might have the same neatening effect on your code...

Copy and paste the code again, in between [code] and [/code] tags, like this:
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
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define ESC 27
#define SPACE 32

int main()
{
    int numArray[10]={31,32,33,34,35,36,37,38,39,40}; // ten boxes in int array and is named x,....
    int index;
    int temp;
    char keynum;

    printf("\tStart/Stop Number Rotation\n");
    printf("\t==========================\n");
    printf("\n");
    printf("\tHit space bar to start number rotation.\n");
    printf("\tTo stop number rotation, hit space bar again.\n");
    printf("\tpress ESC to quit at anytime.\n");
    printf("\n");
    printf("\tHit any key to begin.\n");
    
    system("pause");
    while (true)
    {
        if(kbhit())
        {
            for(index=0 ; index<10 ; index++) 
            {
                printf("%02d ",numArray[index]); //array start from 21-30
                _sleep(100);
            } 

        printf("\t\n");

        for(index=0 ; index<9 ; index++) 
        {
            temp = numArray[index];
            numArray[index] = numArray[index+1];
            numArray[index+1] = temp;

        }
    }
    else if(keynum==SPACE)
    {
        for(index=0 ; index<10 ; index++)
        {
            printf("%02d ",numArray[index]);
            _sleep(100);
        }
    }
        else if(keynum==ESC)
        {
            break; //break out of loop
        }
    }
    printf("Try again?"); 
    printf("\n");

    system("pause");
    return 0;
}


Then it might be legible...
Last edited on
Another helpful thing is to indent well.
Probably messed that up because I do my indenting different.
I was talking to the garcia, not you, sorry. I don't think it is your responsibility to format his code.
erm what is the code tags for? as i have no learnt it yet.
and im not sure wad you mean by this.
''Secondly, you notice how we all write "you" as "you" and not "u"? It's two letters, it really doesn't make a difference to how long it takes you to type. It shows a little effort and willingness to learn.'' sorry my english sux...

http://www.phpbb.com/community/faq.php?mode=bbcode

You're not actually trying to make us believe that you were taught in a foreign language class to write like a retard in English, are you?
Topic archived. No new replies allowed.