Post by keyboardclass on Sept 13, 2010 0:58:57 GMT -5
I see you're studying C Horo. I know nothing about programming. Here's one I did (which I've posted on PW before). It's about testing your short term memory. Anybody written any other simple ones?
added the tags for you :-)
#include <stdlib.h>#include <stdio.h>
#include <time.h>
#include <iostream.h>
#include <conio.h>
#include <windows.h> // WinApi header
int score;
int y;
int t;
int j;
int z;
void sleep ( clock_t wait );
//void thingy ()
void main (void)
{
printf (
"\n Put three fingers on q, w and e. q is 5, w is 4 and e is 3. \n"
"\n Don't type the number you see, type the number you remember seeing two before it.\n"
"\n The computer will beep if you make a mistake. \n"
"\n The object is to get 40 correct as fast as possible.\n"
"\n Remember the first number but for your first entry type anything, then type it.\n"
"\n There will be a beep - even I can't work out what the first entry should be.\n"
"\n To start press y three times followed by return.\n");
play:
j = _getch() - 48;
if (j==65) Beep(262,100);
if (j==71) Beep(294,100);
if (j==53) Beep(330,100);
if (j==66) Beep(350,100);
if (j==70) Beep(392,100);
if (j==64) Beep(659,100);
if (j== 63) Beep(587,100);
if (j==57) Beep(524,100);
if (j==69) Beep(494,100);
if (j==62) Beep(440,100);
if (j < 73) goto play;
else
scanf("%d", y);
start:
long i = 600000L;
clock_t start, finish;
double duration;
//delay
printf ("Wait 3 secounds ...\n");
//Beep(262,300);
//Beep(294,300);
// Beep(330,300);
// Beep(350,300);
// Beep(392,300);
// Beep(440,300);
//Beep(494,300);
//Beep(524,300);
//Beep(587,300);
//Beep(659,300);
//Beep(440,300);
//Beep(392,300);
//Beep(330,300);
//Beep(294,300);
//Beep(262,300);
sleep( (clock_t)3 * CLOCKS_PER_SEC );
printf( "START!\n" );
//measure
//printf( "Time to do %1d empty loops is " , i );
start = clock();
while(i--)
;
void thingy();
{
int k;
int a;
int b;
int counter;
//int c;
//int t;
srand((unsigned)time(NULL));
counter = 1;
//score = 0;
//while (counter <= 2)
{
//b = 2 + (rand()%3);
//printf("%10d", b+1 );
//a=5;
//printf("%10d",b);
}
while (counter <= 40) {
k = 2 + (rand()%3);
//if (k == 1) printf("%10d", k );
//if (k == 5) printf("%60d", k - 4 );
if (k == 2) printf("%60d", 3 );
if (k == 3) printf("%60d", 4 );
if (k == 4) printf("%60d", 5 );
//if (k == 5) printf("%60d", 1 );
//if (k == 6) printf("%60d", 3 );
//if (k > 5) printf("%60d", k - 5 );
// else printf("%10d", k );
//( !_kbhit());
//3-2, 4-3, 5-4, 6-5, 8-6
if (k == 4) Beep(262,100);
if (k == 3) Beep(294,100);
if (k == 2) Beep(330,100);
//if (k == 2) Beep(350,100);
//if (k == 1) Beep(392,100);
//if (k == 10) Beep(659,100);
//if (k == 9) Beep(587,100);
//if (k == 6) Beep(524,100);
//if (k == 7) Beep(494,100);
//if (k == 5) Beep(440,100);
sleep(250);
b=a;
a=z;
z=k;
k=b;
system ("CLS");
j = _getch() - 48;
if (j == 65) (j = 4);
//if (j==4) Beep(262,100);
if (j == 71) (j = 3) ;
//if (j==3) Beep(294,100);
if (j == 53) (j = 2) ;
//if (j==2) Beep(330,100);
//if (j == 66) (j = 2);
//if (j==2) Beep(350,100);
//if (j == 70) (j = 1);
//if (j==1) Beep(392,100);
//if (j == 64) (j = 10) ;
//if (j==10) Beep(659,100);
//if (j == 63) (j = 9) ;
//if (j== 9) Beep(587,100);
//if (j == 57) (j = 6) ;
//if (j==6) Beep(524,100);
//if (j == 69) (j = 7) ;
//if (j==7) Beep(494,100);
//if (j == 62) (j = 5) ;
//if (j==5) Beep(440,100);
//if (j == 4) printf("%d" ,5);
//if (j == 3) printf("%d" ,4);
//if (j == 2) printf("%d" ,3);
//if (j == 1) printf("%d" ,1);
//if (j == 5) printf("%d" ,1);
//if (j == 6) printf("%d" ,3);
//if (j < 6) printf("%d" ,j);
//else printf("%d" ,j - 5);
//printf("%c", _getch());
//printf ("%c\n",j);
//c = (k + j);
//t = (k + k);
//cin >> j;
sleep(500);
if (k == j )
{
counter = counter + 1;
// system ("CLS");
}
if (k != j )
{
printf(" wrong");
{
cout << '\a' << flush;
// system ("CLS");
sleep(1000);
}
//If you want to detect the end of file
//if(cin.eof());
// ...
}
//if (k > j) counter = counter + 1;
//printf("%c",c);
printf("\n");
//counter = counter + 1;
}
}
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf("%2.1f seconds\n\n", duration );
printf("Press any key to start again.\n");
t = _getch();
y = t;
//sleep( (clock_t)3 * CLOCKS_PER_SEC );
goto start;
//printf("%d out of 40\n", score);
//cout << score << " out of 20";
}
//pauses
void sleep( clock_t wait)
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
;
}
//return 0;
//}
added the tags for you :-)