0

Why is this code not working (Why is it showing undeclared all the time)

#include <stdio.h> int main() { char value; printf ("Enter a letter\n"); scanf ("%c", &value); if (value == a) { printf ("A"); } else if (value == b) { printf ("B"); } else if (value == c) { printf ("C"); } else if (value == d) { printf ("D"); } else if (value == e) { printf ("E"); } else if (value == f) { printf ("F"); } else if (value == g) { printf ("G"); } else if (value == h) { printf ("H"); } else if (value == i) { printf ("I"); } else if (value == j) { printf ("J"); } else if (value == k) { printf ("K"); } else if (value == l) { printf ("L"); } else if (value == m) { printf ("M"); } else if (value == n) { printf ("N"); } else if (value == o) { printf ("O"); } else if (value == p) { printf ("P"); } else if (value == q) { printf ("Q"); } else if (value == r) { printf ("R"); } else if (value == s) { printf ("S"); } else if (value == t) { printf ("T"); } else if (value == u) { printf ("U"); } else if (value == v) { printf ("V"); } else if (value == w) { printf ("W"); } else if (value == x) { printf ("X"); } else if (value == y) { printf ("Y"); } else (value == z) { printf ("Z"); } return 0; }

30th Mar 2024, 11:51 AM
Nishit Mehta
Nishit Mehta - avatar
3 odpowiedzi
+ 3
Nishit Mehta in the way that the compiler sees it, variables a, b, c, ..., z are all undefined. I think you intended to compare the input with characters 'a', 'b', 'c', ..., 'z' instead of variables. Make an adjustment to denote single characters with single quotation marks. (Keep the double quotation marks on the scanf() and printf() strings). For example: if (value == 'a') { printf("A"); }
30th Mar 2024, 2:32 PM
Brian
Brian - avatar
+ 2
char declare between '' not "" https://www.learnc.net/c-tutorial/c-character-type/ I hope this helps a bit more :-)
30th Mar 2024, 12:16 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 1
Nishit Mehta , Please add a tag for the language.
30th Mar 2024, 3:34 PM
Rain
Rain - avatar