Where is the error? "system is not declared in this Scope'

Asked

Viewed 3,772 times

-2

I’m supposed to do this https://gyazo.com/ae18e6b29f3ffc73c02f518a73145cc4 I drew this up https://gyazo.com/3729ab0e204f3dc49fff3ec9773155eb

But for the most part of 15 years old he won’t let me write to read the name...

#include <stdio.h>
#include <locale.h>

main(){
    setlocale(LC_ALL,"portuguese");
    int idade;
    char nome;
    printf("Introduza a sua idade\n");
    scanf("%d",&idade);
    switch(idade){
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:printf("Lamentamos mas ainda não tem idade para executar este programa");break;
        default:printf("PARABÉNS Pode prosseguir");
        system("color 8A");
        printf("Digite o seu nome e apelido");
        scanf("%c",&nome);
        printf(" %c você tem %i anos",nome,idade);break;

    }
}

Error says: "system is not declared in this Scope"

  • 1

    Explain the problem too, not to understand very well what is wrong in the code and not what you expect from it by the text of the question.

  • in the last part he does not ask me to type the name and surname

  • Yes I do not understand very well but I think I have done correctly in this code however the last scanf is not working in the program affecting also the printf asseguir....

  • 1

    First understand what is IDE and compiler http://answall.com/q/101691/3635 and then understand what is C and what is C++ http://answall.com/q/19073/3635

1 answer

2


To use the system add the stdlib. h

I switched the switch because it was unnecessary.

Change scanf("%c", &nome); for scanf("%s", nome);, note that I switched %c for %s and removes the & in the name variable, as the reference is unnecessary.

See if this is what you want:

#include <stdio.h>  /* printf */
#include <stdlib.h> /* system */
#include <locale.h> /* setlocale */

int main()
{
    setlocale(LC_ALL, "portuguese");

    int idade;
    char nome[80]; //limitei o char para 80

    printf("Introduza a sua idade\n");
    scanf("%d", &idade); //int requer referencia

    if (idade > 15) {
        system("color 8A");
        printf("PARABÉNS Pode prosseguir\n");
        printf("Digite o seu nome e apelido\n");

        scanf("%s", nome);
        printf("%s você tem %i anos\n", nome, idade);
    } else {
        printf("Lamentamos mas ainda não tem idade para executar este programa\n");
    }

    return 0;
}

In case I used if and else:

if (idade > 15) {

The switch can be used better otherwise, I recommend you try to study the basics of if, while, for, switch to understand what you’re doing

I recommend you read:

  • It’s a mistake. I pulled the break but it still says 'system is not declared in this Scope''

  • compiler? I use c++ dev and write to c source

  • hmm, still with the same error that presented in my switch initial, do not ask me to enter the name.

  • You’re always in the same trouble... :/

  • Never mind, help has already helped me understand better what I was doing wrong, now just fix that part of the exit. Then I’ll talk to my Tora and she’ll help me with the rest :)

  • In that part it continues to do the code the same way when compiling in c++ and in c source it says that it does not have the library you added

  • https://gyazo.com/ad9debf52f6e6157b16036cca9d1c0d2

  • @Nopenope did not understand, by your screen print (screen) seems to have entered the if. Or is the scanf that is not working?

  • is the scanf that does not give :7

  • I can’t run because there’s no library

  • @Nopenope updated the code and put some explanations

  • I already realized :), after all until the program I had done on switch was fine, the problem was the output to be in char and not in string. By the way, do you know of a post here or another site that explains the basics of while,for,if and Else? I’m also having a lot of difficulty with this part because I don’t understand its correct function and how the variables are identified.

Show 7 more comments

Browser other questions tagged

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