One of the most favorite works of my freshman. At first, it was just a little program that could automatically emit little Star music. XD
:
The code is as follows:
/*this is a small piano. This is a little piano oh ~*/#include <stdio.h> #include <conio.h>/non-buffered input #include<stdlib.h># include<windows.h> #pragma warning (disable:4996)//to use Getche () in VS needs it#define TICK 450#define DOH 523#def Ine RAY 587#define MI 659#define FA 698#define SOH 784#define LA 880#define TEE 980#define dohh 1060#define RAYH 1 175#define MIH 1318#define FAH 1397#define sohh 1568#define LAH 1760#define teeh 1976void welcome (void); void Displa Y (void); void Playmusic1 (void); Play Music with colorvoid playmusic2 (void); Play Music without colorvoid thanks (void); void choose1 (void); Choose a typevoid choose2 (void); Choose a songvoid song1 (void), void song2 (void), Char a;int choice,choice2;int main (void) {welcome (); if (choice = = 2) { printf ("Enter numbers to play music: [' P ' to quit] \ n"), while (1) {playmusic1 (); if (a = = ' P ') break;}} else{printf ("Choose the song you want to Play:\n" "1.Castle in the Sky (City of Heaven) \n2. Star in moistened Hishinuma (where the star is located) \ n"); Choose2 (); thanKS (); return 0;} void welcome (void) {Setconsoletextattribute (GetStdHandle (std_output_handle),;p rintf ("1-doh 2-ray 3-mi numbers 1 to 7, Letter Q\n "" 4-fa 5-soh 6-la wertyu corresponding scale \ n "" 7-tee q-dohh w-rayh\n "" E-mih r-fah t-soh\n "" Y-lah u-teeh\n ");d Isplay (); Choose1 ();} void display (void) {int i;for (i = 0; i <; i++) printf ("=");} void Choose1 (void) {printf ("Choose A game Type:\n1.play songs (play mode) \t2.free Play (free mode) \ n"), while ((scanf ("%d", & Choice)) = 1) {while (GetChar ()! = ' \ n ');p rintf ("Please enter a number ~");} Display ();} void Choose2 (void) {while ((scanf ("%d", &choice2)) = 1) {while (GetChar ()! = ' \ n ') printf ("Please enter a number ~");} Display (); if (Choice2 = = 1) song1 (), Else song2 ();p rintf ("Enter numbers to play Music: (' P ' to quit) \ n"); while (1) {Playmusic 2 (); if (a = = ' P ') break;}} void Playmusic1 (void)//audible and set color {a = Getch (); switch (a) {case ' 1 ': Beep (DOH, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 30); printf ("DOH"); Break;case ' 2 ': Beep (RAY, TICK); SetConsoletextattribute (GetStdHandle (Std_output_handle), 60); printf ("RAY"); Break;case ' 3 ': Beep (MI, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 90); printf ("MI"); Break;case ' 4 ': Beep (FA, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 120); printf ("FA"); Break;case ' 5 ': Beep (SOH, TICK); Setconsoletextattribute (GetStdHandle (std_output_handle), 150); printf ("SOH"); Break;case ' 6 ': Beep (LA, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 180); printf ("LA"); Break;case ' 7 ': Beep (TEE, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 210); printf ("TEE"); Break;case ' Q ': Beep (dohh, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 30); printf ("dohh"); Break;case ' W ': Beep (Rayh, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 60); printf ("Rayh"); Break;case ' E ': Beep (MIH, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 90); printf ("MIH"); Break;case ' R ': Beep (FAH, TICK); SetconsoletExtattribute (GetStdHandle (Std_output_handle), 120); printf ("FA"); Break;case ' t ': Beep (sohh, TICK); Setconsoletextattribute (GetStdHandle (std_output_handle), 150); printf ("SOH"); Break;case ' y ': Beep (LAH, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 180); printf ("LA"); Break;case ' u ': Beep (Teeh, TICK); Setconsoletextattribute (GetStdHandle (Std_output_handle), 210); printf ("TEE"); Break;case ' \ n ': Break;default:break;}} void Playmusic2 (void)//audible {a = Getch (); switch (a) {case ' 1 ': Beep (DOH, TICK); Break;case ' 2 ': Beep (RAY, TICK); Break;case ' 3 ': Beep (MI, TICK); Break;case ' 4 ': Beep (FA, TICK); Break;case ' 5 ': Beep (SOH, TICK); Break;case ' 6 ': Beep (LA, TICK); Break;case ' 7 ': Beep (TEE, TICK); Break;case ' Q ': Beep (dohh, TICK); Break;case ' W ': Beep (Rayh, TICK); Break;case ' E ': Beep (MIH, TICK); Break;case ' R ': Beep (FAH, TICK); Break;case ' t ': Beep (sohh, TICK); Break;case ' y ': Beep (LAH, TICK); Break;case ' u ': Beep (Teeh, TICK); Break;case ' \ n ': Break;default:break;}} void Thanks (void) {Putchar (' \ n '); Setconsoletextattribute (GetStdHandle (std_output_handle),;d isplay ();p rintf ("Thanks for playing~~~\n"); System (" Pause ");} void song1 (void)//Sky City {printf ("67q7qe7 3656q5 3434q3 \ n");} void Song2 (void)//star where {printf ("Q7qe7 656q5 434q75 67QEW q7qe75 67QWE rewq7e\n");}
Copyright NOTICE: Welcome reprint (^ω^) ~ But reprint please indicate source: Http://blog.csdn.net/catglory? (????)
Keyboard piano [C language] [homemade]