what is the int opc for? in c ++? [closed]

0
#include <conio.h>
#include <stdio.h>

int main( ) {
  int opc; // <- porque el termino opc?

  printf( "\n Por favor introduzca un numero del 1 al 7 considerando 1 como lunes " );
  scanf( "%d", &opc );

  switch( opc ) {
  case 1:
    printf( "\n El dia es lunes" );
    break;

  case 2:
    printf( "\n El dia es martes" );
    break;

  case 3:
    printf( "\n El dia es miercoles" );
    break;

  case 4:
    printf( "\n El dia es jueves" );
    break;

  case 5:
    printf( "\n El dia es viernes" );
    break;

  case 6:
    printf( "\n El dia es sabado" );
    break;

  case 7:
    printf( "\n El dia es domingo" );
    break;

  default:
    printf( "\n El numero que has incertado no es el correcto, intenta del numero 1 al 7" );
  }
}
    
asked by Redes del Hack 05.11.2017 в 02:31
source

3 answers

2

When programming, you have to resort to using variables to store information sooner rather than later.

It is advisable, for the program to be readable (which makes the appearance of errors difficult and facilitates the tasks of debugging and maintenance), is that these variables have significant names about their usefulness.

The names are, yes, free in any case.

int opc;

In this line an integer variable is being declared and that variable has been given the name opc . Why that name and not another? Because it is the one who has chosen the one who wrote the program ... who could also have chosen tengounavaraiblequenosecomonombrar , but who chose the same% opc because it seems descriptive enough.

    
answered by 05.11.2017 в 19:35
1

opc can be "options". Actually, a whole Int number and a name for that variable are declared. In scanf, the variable is given a value from the keyboard and the value entered is compared in the switch. If it is not between the expected values, it is printed on the screen that is correct.

    
answered by 05.11.2017 в 05:28
0

Note that opt is not a global variable of C / C ++, much less a function of the language. It is the name that the person who wrote the code has used to refer to an integer variable. As you have explained, probably called it that way because it is similar to an option entered by keyboard.

    
answered by 05.11.2017 в 09:58