Thread: Soundboard Application in Console

  1. #1
    Registered User
    Join Date
    Oct 2021
    Posts
    2

    Soundboard Application in Console

    For my programming class I am attempting to make a soundboard of 5 sounds. A user can type in a number 1-5 to play a specific sound. I am quite new to programming so I have been looking online for help and I found a solution that gives me no errors except the sound still does not play. I do not know if my code is even good. I am not asking for someone to write me a code more looking for some hints or tips on how I could make it function or an easier way than what I did.
    Code:
    #include <stdio.h>
    #include <Windows.h>
    
    
    //Start of Soundboard Application
    int main(void) 
    {
        int songChoice;
    
    
                                                                                                   
        printf("Welcome to Austin's Soundboard!\n");
        printf("1.) Windows XP Startup Sound\n");
        printf("2.) Windows XP Critical Stop Sound\n");
        printf("3.) Windows XP Tada Sound\n");
        printf("4.) Windows XP Notification Sound\n");
        printf("5.) Windows XP Chimes Sounds\n\n");
    
    
        printf("What sound effect would you like to hear? (1-5): ");
    
    
        scanf_s("%d", &songChoice);
    
    
        if (songChoice == 1)
            PlaySound(TEXT("startup.wav"), NULL, SND_FILENAME, SND_SYNC);
    
    
        if (songChoice == 2)
            PlaySound(TEXT("critical.wav"), NULL, SND_FILENAME, SND_SYNC);
    
    
        if (songChoice == 3)
            PlaySound(TEXT("tada.wav"), NULL, SND_FILENAME, SND_SYNC);
    
    
        if (songChoice == 4)
            PlaySound(TEXT("notify.wav"), NULL, SND_FILENAME, SND_SYNC);
    
    
        if (songChoice == 5)
            PlaySound(TEXT("chimes.wav"), NULL, SND_FILENAME, SND_SYNC);
        
    
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    PlaySound function (Windows) | Microsoft Docs
    1. Trying to pass 4 parameters to a function expecting only 3 should have at least got you a warning message.
    It should be an error.

    The last 'two' parameters are supposed to be or-ed together, like this.
    PlaySound(TEXT("startup.wav"), NULL, SND_FILENAME | SND_SYNC);

    2. PlaySound returns a result.
    If things don't work, your first course of action should be to investigate the error returns any functions you're using, to see if that provides you with clues.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2021
    Posts
    2
    Thank you so much it works now! Thank you for explaining that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C (Not ++) Console Application
    By MittWaffen in forum C Programming
    Replies: 16
    Last Post: 10-10-2010, 08:15 AM
  2. Console Application
    By llcool_d2006 in forum C++ Programming
    Replies: 11
    Last Post: 11-04-2006, 03:46 PM
  3. console application...
    By k1ll3r in forum C++ Programming
    Replies: 4
    Last Post: 05-23-2006, 10:41 AM
  4. Console Application
    By Mont_Blanc in forum C++ Programming
    Replies: 3
    Last Post: 04-17-2004, 03:07 AM
  5. GUI Application --> Console
    By Student040314 in forum C++ Programming
    Replies: 2
    Last Post: 03-14-2004, 01:30 PM

Tags for this Thread