Instruction Write a C program that prompts the user to desig
Solution
// Include the standard input/output header file and declare all constants
#include<stdio.h>
#include<string.h>
#include<windows.h>
#define FILENAME \"music.txt\"
#define N 50
int main(void)
{
int k=0, length, speed[N];
// Frequency of notes
double A=440.00, B=493.88, C=523.25, D=587.33, E=659.26, F=698.46, G=783.99;
double a=466.16, c=554.37, d=622.25, f=739.99, g=830.61;
HANDLE hConsole;
char *myString;
FILE *music;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
printf(\"The program will play music in one octive from A to G.\ To play a\"
\" note use the upper case letter. For a sharp use the lower case\"
\" letter. If you would like a small break use the \'space\'.\ You must \"
\"create the entire song in a txt file called \'music.txt\'\ \");
music = fopen(\"music.txt\", \"r\");
// Checking to make sure the file is there
if(music==NULL)
printf(\"file not found\ \");
else
{
// Scanning the file for the music notes and length of note
while(fscanf(music, \"%c%d\ \", &myString[k], &speed[k])==2)
{
printf(\"%c %i\ \", myString[k], speed[k]);
k++;
}
// Checking length of string
length = strlen(myString);
// Setting the length of each note into miliseconds
for(k=0;k<length;k++)
{
if(speed[k]==1)
speed[k]=100;
if(speed[k]==2)
speed[k]=200;
if(speed[k]==3)
speed[k]=300;
if(speed[k]==4)
speed[k]=400;
}
// Playing the music
for(k=0;k<length;k++)
{
if(myString[k]==\'a\')
Beep(a,speed[k]);
if(myString[k]==\'c\')
Beep(c,speed[k]);
if(myString[k]==\'d\')
Beep(d,speed[k]);
if(myString[k]==\'f\')
Beep(f,speed[k]);
if(myString[k]==\'g\')
Beep(g,speed[k]);
if(myString[k]==\'A\')
Beep(A,speed[k]);
if(myString[k]==\'B\')
Beep(B,speed[k]);
if(myString[k]==\'C\')
Beep(C,speed[k]);
if(myString[k]==\'D\')
Beep(D,speed[k]);
if(myString[k]==\'E\')
Beep(E,speed[k]);
if(myString[k]==\'F\')
Beep(F,speed[k]);
if(myString[k]==\'G\')
Beep(G,speed[k]);
if(myString[k]==\' \')
sleep(speed[k]);
}
// Closing the open file
fclose(music);
}
system(\"pause\");
return (0);
}

