Problem with simple C ++ code

1

the code must analyze if it is greater or lesser in age, and throw a result on the screen, but it gives an error.

#include <stdio.h>

using namespace std;

int main ()

{
    int edad;
    cin >> edad ;
    cout << "ingrese su edad: " ;

    if (edad >=18)

{   
    printf << "usted es mayor de edad" << endl;
}

else

{
    printf << "usted es menor de edad" << endl;
}

system ("pause");
}
    
asked by Lux 22.08.2018 в 02:35
source

4 answers

3

1) There is an option to add code.

2) It is very useful if you include the error too.

It is very likely that you are not aging at any age because you make the cin before the cout

You are also using printf instead of cout

printf uses a structure like this

 printf ("mensaje\n");
    
answered by 22.08.2018 в 02:47
1

I miss your return 0; You could also include #include and remove stdio.h, take care of the syntax of your code, and in previous comments they told you about using cout.

    
answered by 24.08.2018 в 20:00
1

There are basically 2 errors, the first is that you are using the cin before cout, that is, you first read the value that will be given to the variable age and then print it, when it will be useful to request the value first.

The second error is the use of printf with cout syntax like this:

printf << "usted es menor de edad" << endl;

you can use:

cout << "usted es menor de edad" << endl;
    
answered by 25.08.2018 в 02:18
1

Welcome to Stack Overflow.

The error is that you are using printf instead of cout .

Printf is a function inherited from C, so it is hardly likely to be overloaded by the insertion operator.

Also, I think you should first print the message asking for age and then read it by keyboard:

int edad;
cout << "ingrese su edad:"; 
cin >> edad ;
    
answered by 22.08.2018 в 03:48