pastebin

Paste Search Dynamic
Recent pastes
beep frequency duration
  1. #include <iostream>
  2. #include <chrono>
  3. #include <thread>
  4.  
  5. using namespace std;
  6.  
  7. void beep(int frequency, int duration) {
  8.     for (int i = 0; i < duration * frequency / 1000; i++) {
  9.         cout << "a";
  10.         this_thread::sleep_for(chrono::milliseconds(1));
  11.     }
  12. }
  13.  
  14. int main() {
  15.     int melody[] = { 440, 440, 440, 349, 523, 440, 440, 440, 349, 523, 440, 440, 440, 349, 523, 440, 523, 523, 587, 523, 466, 523, 440 };
  16.     int duration[] = { 500, 500, 500, 500, 500, 1000, 500, 500, 500, 500, 1000, 500, 500, 500, 500, 1000, 500, 500, 500, 250, 500, 500, 1000 };
  17.     int length = sizeof(melody) / sizeof(melody[0]);
  18.  
  19.     for (int i = 0; i < length; i++) {
  20.         beep(melody[i], duration[i]);
  21.     }
  22.  
  23.     cout << "Selamat ulang tahun!" << endl;
  24.     cout << "Semoga panjang umur, sehat selalu, dan sukses dalam segala hal." << endl;
  25.  
  26.     return 0;
  27. }
  28.  
Parsed in 0.016 seconds