Error in variable type

Asked

Viewed 54 times

0

What fix do I have to make this code run without error?

#include <iostream>

using namespace std;

int main(int argc, char** argv) {

    int anoNasc, idade, anoAtual = 2020;
    char categoria;

    cout <<"Digite o ano de nascimento: ";
    cin >> anoNasc;
    idade = anoAtual - anoNasc;

    if (idade >= 7 && idade <= 12){

        categoria = "Infantil";
    }
    cout <<"Sua "<<idade<<" anos sua categoria é"<<categoria;

    return 0;
}
  • 1

    Study data types in C/C++. When declaring char categoria; you are saying that the category variable buys a single character and not a string.

  • Yes, and always read carefully the error that the compiler shows. There will be information to help you identify what is wrong with the code

1 answer

4


To solve the problem described you must change the type of the variable categoria for string, the type you used only allows a character and not a whole text.

Don’t forget to do the include <string>.

  • Thanks, here it worked out. vlw.

Browser other questions tagged

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