-1

I am trying to make a simple app that plays a sound when pressing a specific number but whatever I enter it plays the first song for some weird reason.

#include <stdio.h>
#include <Windows.h>
#include "MMsystem.h"

void main(void){

    printf("\t\t\t\t\t\tCh00se A M3m3\n\n");
    printf("\t\t\t\t\t\t1.Quick Maths\n");
    printf("\t\t\t\t\t\t2.Crippling Deprresion");

    int MemeNumber;
    scanf_s("%d", &MemeNumber);
    if (MemeNumber = "1")
    {
        PlaySound(TEXT("BigShaq.wav"), NULL, SND_SYNC);
    }

    if (MemeNumber = '2')
    {
        PlaySound(TEXT("CripplinD.wav"), NULL, SND_SYNC);
    }

    getch();
}
Clifford
  • 88,407
  • 13
  • 85
  • 165
Adam.A.T.
  • 7
  • 1

1 Answers1

2

if (MemeNumber = "1")

  1. MemeNumber is an int and "1" is a char*/string
  2. = is an assignment, not a compare.

if (MemeNumber = '2')

  1. MemNumber is an intand '2' is a char.
  2. = is an assignment not a compare.

Try if (MemeNumber == 1) and if (MemeNumber == 2). Also: have a look at the switch statement. It will help simplify your code.

Note: If you compiled with all the warnings turned on, the compiler would highlight all of this for you.

John3136
  • 28,809
  • 4
  • 51
  • 69