- 分享
- 0
- 人气
- 0
- 主题
- 7
- 帖子
- 4707
- UID
- 82675
- 积分
- 5108
- 阅读权限
- 22
- 注册时间
- 2007-6-18
- 最后登录
- 2021-7-27
- 在线时间
- 5767 小时
|
原帖由 shetaikeng 于 2009-8-2 09:52 PM 发表
那请问要如何更改???
我也不知道要如何declare variables
那麼可否問一下, 到目前為止以下這部分是你本身寫的嗎?? 要是真的是你寫的那麼應該知道甚麼是 declaration
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define ESC 27
#define u 117
#define d 100
void UPP();
void DOWN();
int ChangeTime(int);
//creating a GLOBAL integer array of 10 elements
int numArray[]={1,2,3,4,5,6,7,8,9,10};
int time=1;
char key;
int index;
int temp;
int main()
{
do
{
system("cls");
//display the outlook
printf("\tUp/Down Number Rotation\n");
printf("\t=========================\n\n");
printf("\tEnter [U] for up rotation\n");
printf("\tEnter [D] for down rotation\n");
printf("\tTo stop rotation, any key except [U],[D],[ESC]\n\tPress ESC to quit at anytime.\n\n");
printf("\tHit any key to start\n\n\t");
key=getch();
do
{
for (index=0; index<10; index++)//rotate
{
printf("%02d ",numArray[index]);
_sleep(time*100);
}
printf("\tTime=0.%ds -STOP KEY\n\t\a",time);
if(kbhit())
{
key=getch();
while(key!=ESC)
{
switch(key)
{
case'u':UPP();break;
case'd': DOWN();break;
case'1':ChangeTime(1);break;
case'2':ChangeTime(2);break;
case'3':ChangeTime(3);break;
case'4':ChangeTime(4);break;
case'6':ChangeTime(6);break;
case'7':ChangeTime(7);break;
case'8':ChangeTime(8);break;
case'9':ChangeTime(9);break;
}
if(key!=u && key!=d)//if neither "u" nor "d" is hit
{
break;//breaky the while loop to go back to STOP KEY mode
}
}
}//end of kbhit()
}while(key != ESC );//end of the rotation
printf("Try again?");
key=getch();
}while(key!='n');//end of do-while loop
printf("\n");
system("pause");
return 0;
}
void UPP()
{
while(key==u && key!=ESC && key!=d)
{
/* using for-loop to shift all 10 elements in one go */
for(index=0; index<9; index++)
{
temp = numArray[index+1]; // moving the element content pointed by index to a temporary location
numArray[index+1] = numArray[index]; // moving the next element contect to the element content pointed by index
numArray[index] = temp ; // moving the element content pointed by index from the temporary location to the next element content pointed by index
}
for(index=0; index<10; index++)
{
printf("%02d ",numArray[index]);
_sleep(time*100);
}
printf("\tTime=0.%ds -UP KEY\n\t\a",time);
if(kbhit())
{
key=getch();
switch(key)
{
case'1':ChangeTime(1);break;
case'2':ChangeTime(2);break;
case'3':ChangeTime(3);break;
case'4':ChangeTime(4);break;
case'6':ChangeTime(6);break;
case'7':ChangeTime(7);break;
case'8':ChangeTime(8);break;
case'9':ChangeTime(9);break;
}
break;
}// a key is detected again and it's not u
}//end of upp key while loop
}
void DOWN()
{
while(key!=ESC && key!=u && key==d)
{
/* using for-loop to shift all 10 elements in one go */
for(index=9; index>0; index--)
{
temp = numArray[index]; // moving the element content pointed by index to a temporary location
numArray[index] = numArray[index-1]; // moving the next element contect to the element content pointed by index
numArray[index-1] = temp ; // moving the element content pointed by index from the temporary location to the next element content pointed by index
}
for(index=0; index<10; index++)
{
printf("%02d ",numArray[index]);
_sleep(time*100);
}
printf("\tTime=0.%ds -DOWN KEY\n\t\a",time);
if(kbhit())
{
key=getch();
switch(key)
{
case'1':ChangeTime(1);break;
case'2':ChangeTime(2);break;
case'3':ChangeTime(3);break;
case'4':ChangeTime(4);break;
case'6':ChangeTime(6);break;
case'7':ChangeTime(7);break;
case'8':ChangeTime(8);break;
case'9':ChangeTime(9);break;
}
break;
}// a key is detected again and it's not u
}//end of upp key while loop
}
int ChangeTime(int InputTime)
{
time=InputTime;
} |
|