Pause in C ++ pause does not work when running the.exe

0

At the moment of executing the .exe of a program in c ++ it does not pause, that is to say it closes of blow and I do not understand because it happens since I have a "getch" and a (pause))

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

int main()
{
//    int ingles;
//    char nivel[10];
//    printf( "\n   QUE NIVEL DE INGLES CREES QUE TIENES?: " );
//    scanf( "%s","&nivel");


    char r1[10];
    char r2[10];
    char r3[10];
    char respuesta1[] = "eaten";
    char respuesta2[] = "clever";
    char respuesta3[] = "pretty";

    int num_correctas = 0;
    int num_incorrectas = 0;

    printf( "\n  Escribe la palabra que falta-i have never.... indian food-" );  
    gets(r1);

    if (strcmp(respuesta1,r1) == 0 )
    {
       printf( "\n  correcto");
       num_correctas = num_correctas + 1;
    }
    else
    {
      printf( "\n  incorrecto");
      num_incorrectas = num_incorrectas + 1; 
    }

       printf( "\n    sinonimo de +intelligent+-" );  
    gets(r2);

    if (strcmp(respuesta2,r2) == 0 )
    {
       printf( "\n  correcto");
       num_correctas = num_correctas + 1;
    }
    else
    {
      printf( "\n  incorrecto");
      num_incorrectas = num_incorrectas + 1; 
    }

    printf( "\n sinonimo de +beautiful+- " );  
    gets(r3);

    if (strcmp(respuesta3,r3) == 0 )
    {
       printf( "\n  correcto");
       num_correctas = num_correctas + 1;
    }
    else
    {
      printf( "\n  incorrecto");
      num_incorrectas = num_incorrectas + 1; 
    }

    printf("\n Numero de respuestas correctas: %d", num_correctas);
    printf("\n Numero de respuestas incorrectas: %d", num_incorrectas);
    return 0;

   ("PAUSE()"); 
    getch();
}
    
asked by Ricardo 15.04.2018 в 03:04
source

1 answer

1

Your error is that you call return before doing the pause, since your return ends the program, which is why it does not pause you.

Another error is ("PAUSE()"); , code that does not call any function, maybe you need to do system("pause") , which will print a message: Press a key to continue. . . , on your console.

Another thing is that you use getch(); , code that you expect a key to be pressed to continue. You could say it's a pause without any kind of message.

So in the end you can use only one of the two options [ system("pause") or getch(); ].

Your last lines of code would be as follows:

system("pause");
return 0;

Keep in mind that this code will only work on Windows operating systems.

Or

getch();
return 0;

Case that was used in language C .

So in C++ you have a better option:

cin.get();
return 0;
    
answered by 15.04.2018 в 15:41