Adblock breaks this site

Internal Beep Program

Discussion in 'Programming General' started by agent766, Oct 29, 2008.

  1. agent766

    agent766 Guest

    Referrals:
    0
    Internal Beep Program

    Here's basically a simple program I made to REALLY annoy my friends. 10kHz is awesome at annoying people ;)

    Code:
    #include <iostream>
    #include <windows.h>
    
    int main() {
    do {
         cout << "Frequency: ";
         cin >> x;
         cout << endl << "Duration: ";
         cin >> y;
    
         Beep(x,y);
         System("CLS");
    } while(true);
    }
     
  2. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Internal Beep Program

    Mind telling me where you declared variables 'x' and 'y'?

    Also, you could just use escape characters to achieve the same thing.

    Code:
    printf("\a");
    omits a system beep.
     
  3. theory_

    theory_ Active Member

    Joined:
    Oct 3, 2008
    Posts:
    119
    Referrals:
    0
    Sythe Gold:
    0
    Internal Beep Program

    By convention, his main should return something too. agent766, should also use k&r style scoping. A better control flow statement might have just been using a while statement(less typing). And variable x, and y are not declared.
     
  4. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Internal Beep Program

    Ehh, do-while has a subtle difference though. It actually executes once beforehand regardless of the condition set in the while loop. But I agree for the most part.
     
  5. Teh_Uber_Codex

    Teh_Uber_Codex Member
    Banned

    Joined:
    Nov 22, 2008
    Posts:
    75
    Referrals:
    0
    Sythe Gold:
    0
    Internal Beep Program

    Thanks SWAN.

    ~Uber
     
  6. xedon

    xedon Newcomer

    Joined:
    Nov 18, 2007
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0
    Internal Beep Program

    Try this;

    #include <iostream>
    #include <windows.h>

    using namespace std;

    int i;
    int freqa;
    int lengtha;
    int lengtht;
    int waita;
    int waitt;
    int timesa;




    int main() {

    cout << "How long would you like it to play for in seconds: ";
    cin >> lengtht;
    cout << "What frequency would you like to play at (about 20-200): ";
    cin >> freqa;
    cout << "How many times would you like this to be played: ";
    cin >> timesa;
    cout << "How long should we wait in between each beep in seconds: ";
    cin >> waitt;

    lengtha = lengtht*1000;
    waita = waitt*1000;
    for(i= 0; i < timesa; i++) {
    Beep(freqa,lengtha);
    Sleep(waita);
    }

    }
     
  7. d great one

    d great one Apprentice

    Joined:
    Nov 4, 2007
    Posts:
    930
    Referrals:
    2
    Sythe Gold:
    0
    Internal Beep Program

    very long declaration of int :D.

    You could just state

     
< Help W/ Buttons | If you need help.... >


 
 
Adblock breaks this site