I cannot identify the error - |35|error: ’d' undeclared (first use in this Function)|

Asked

Viewed 1,979 times

0

I am programming in C/C++ and gave an error that I cannot identify it.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

//Função Principal do Programa
 int main() {

      //Definindo variáveis
      int a = 5, b = 10, c = 15;

      //Maior
      if(a > 2){
         printf("\n %d Eh maior que 2\n", a);
      }

      //Maior ou Igual
      if(c >= b){
        printf("\n %d Eh maior ou igual a %d\n", c, b);
      }

      //Menor
      if(a < 10){
        printf("\n %d Eh menor que 10\n", a);
      }

     //Menor ou Igual
     if(a <= 10){
        printf("\n %d eh menor ou igual a 10\n", a);
     }

     //Diferente
      if(c != 10){
         printf("\n %d nao eh 10\n", c);
     }
      if(d != 'a'){
            printf("\n %c nao eh a", d);
     }

     //Pausa o Programa após executar
     system("pause");

}
  • Not that it changes to this case, but you need to decide if you’re programming in C or C++, you can’t do both.

  • Really, but I’m taking the c and c++ fundamentals course so since I’m a beginner I don’t know if I’m programming in c or c++ (I think c++), I understand your answer, every day that passes my knowledge increases gradually, I’d rather you had a list of "commands" to know correctly declare a variable or something like kkkk. But thank you for your attention and your reply helped me a lot.

  • It should be the first thing that the course talks about. Besides, if the course says that it is amos, the course already has problems. There is no C++ line in this code, although Compile in C compiler++.

  • True, I agree with every word said above, and searching lists of commands I realized that even the language used is C. Now regarding the institution, it is not the best but I do Analysis and system development and I will have programming this semester, I just don’t know if I’ve found the best way. A e além de "adiantar" I’m adding knowledge to my resume because I need to work. Thanks for commenting man.

  • 1

    Adding knowledge is not a good way, it is better to learn and this is done in a structured way, with correct information, in order, on a previous basis. You can ask whatever you want here to learn, as long as you’re on time.

  • Thank you, I saw your profile and you teach courses?

  • 1

    No, but I’m thinking about it, the problem is that I think most people wouldn’t like my courses, people like the courses "cheat me that I like", I would do something well pulled, that goes deep, that teaches even, that tells the guy to go further, which shows that it is necessary to question and not just absorb, people do not like it very much. But guess who likes it a lot? The job market. But who makes the decision about what course to do is the person, market has no conscience. Of any adds me in some network, maybe something comes out.

Show 2 more comments

1 answer

3


As the message itself indicates, the variable remains to be declared d. You’re wearing it on the last if without it existing. A solution would be:

int a = 5, b = 10, c = 15
char d = 'a';

I put in the Github for future reference.

  • Gee, thanks man but I’d actually forgotten the char d = 'x'; I can’t tell exactly what it’s for but it was that, but if it wasn’t for you I wouldn’t have come to that conclusion. Thank you.

  • @dzarm is, I didn’t even notice that the last one was different, I corrected now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.