You’re confusing the assignment operator =
with the equals operator ==
. Write this instead:
if (battlechoice == 4)
And so on.
Some C programmers use “Yoda conditionals” to avoid accidentally using assignment in these cases:
if (4 == battlechoice)
For example this won’t compile, catching the mistake:
if (4 = battlechoice)
Related Contents:
- How can I read an input string of unknown length?
- What is the effect of trailing white space in a scanf() format string?
- Why is scanf() causing infinite loop in this code?
- Disadvantages of scanf
- How to do scanf for single char in C [duplicate]
- Simple C scanf does not work? [duplicate]
- Why does scanf() need “%lf” for doubles, when printf() is okay with just “%f”?
- C: Multiple scanf’s, when I enter in a value for one scanf it skips the second scanf [duplicate]
- Program doesn’t wait for user input with scanf(“%c”,&yn);
- C – scanf() vs gets() vs fgets()
- What does the scanf function return?
- How do you allow spaces to be entered using scanf?
- How to use sscanf in loops?
- C/C++ printf() before scanf() issue
- C skipping one command of a function? [duplicate]
- Parsing input with scanf in C
- scanf: “%[^\n]” skips the 2nd input but ” %[^\n]” does not. why?
- abnormal behavior of scanf [duplicate]
- Using “\n” in scanf() in C [duplicate]
- Reading in double values with scanf in c
- What does space in scanf mean? [duplicate]
- Difference between scanf and scanf_s
- Reading a line using scanf() not good?
- Does scanf() take ‘\n’ as input leftover from previous scanf()?
- What is the difference between sscanf or atoi to convert a string to an integer?
- Why scanf must take the address of operator
- fgets instructions gets skipped.Why?
- printf not printing on console
- Problems with C scanf(“%c”) function to read characters one by one
- Going through a text file line by line in C
- scanf(“%c”) call seems to be skipped
- Input in C. Scanf before gets. Problem
- Reading a single character in C
- How do we test the return values from the scanf() function?
- Why does a space in my scanf statement make a difference? [duplicate]
- Scanf won’t execute for second time
- How can I prevent scanf() to wait forever for an input character?
- scanf() variable length specifier
- Reading a string with spaces with sscanf
- What does `scanf(“%*[^\n]%*c”)` mean?
- While-loop ignores scanf the second time
- Dynamic String Input – using scanf(“%as”)
- Using scanf and fgets in the same program?
- Max string length using scanf -> ANSI C
- Whitespace before %c specification in the format specifier of scanf function in C
- SegFault after scanf?
- Why scanf(“%d”, […]) does not consume ‘\n’? while scanf(“%c”) does?
- What is the format specifier for unsigned short int?
- Compound condition in C: if (0.0 < a < 1.0)
- Program doesn’t execute gets() after scanf(), even using fflush(stdin)