/* this program reads a frequency and a time from the terminal and generates a beep for the prescribed pitch and time. As part of error checking, the frequency must be between 800 and 4200, and the user is asked to re-enter any value outside this range. the time must be positive and less than 5.0, and the user is asked to re-enter any time outside this range. */ #include #include int main () { /* preliminaries */ printf ("program to generate a beep for a prescribed frequency and time\n"); rConnect ("/dev/rfcomm0"); int freq; double time; /* first read frequency */ do { printf ("enter a frequency between 800 and 4200, inclusive"); scanf ("%d", &freq); if ((freq < 800) || (freq > 4200)) { printf ("frequency must be between 800 and 4200, try again\n"); } } while ((freq < 800) || (freq > 4200)) ; /* second read time */ do { printf ("enter a positive time less than 5.0"); scanf ("%lf", &time); if ((time < 0) || (freq >= 5.0)) { printf ("time must be between 0.0 and 5.0, try again\n"); } } while ((time <0.0) || (time >= 5.0)) ; printf ("frequency and time are read: here comes the beep!\n"); rBeep (time, freq); /* wrap up */ rDisconnect (); printf ("program completed\n"); return 0; }