c++ - How to play sound when timer reaches zero? -


i trying make timer , have play sound @ end. have made timer , works fine sound won't play. have far:

int main() {     //cout << "this timer. still in making seconds work properly." << endl;     //sleep(7000);     //system("cls");      int input;      cout << "enter time: ";     cin >> input;     cout << endl << "begin." << endl;     system("cls");      while (input != 0) {         input--;         cout << input << " seconds" << endl;         sleep(200);         system("cls");          if (input == 0) {             playsound(text("c:\\users\\id student\\downloads\\never_gonna_hit_those_notes.wav"), null, snd_filename | snd_async);         }     } } 

as others have mentioned, snd_async flag culprit, need remove it.

i suggest restructure code move playsound() outside of loop. there no point in checking input 0 multiple times in loop. code after loop called when loop ends:

const char* plural[] = {"", "s"};  int main() {     int input;      cout << "enter # of seconds: ";     cin >> input;      system("cls");     cout << "begin." << endl;      while (input > 0)     {         system("cls");         cout << input << " second" << plural[input != 1] << endl;         sleep(1000);         --input;     }      system("cls");     cout << "done." << endl;      playsound(text("c:\\users\\id student\\downloads\\never_gonna_hit_those_notes.wav"), null, snd_filename);      return 0; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -