I was wondering if there is another way to prevent a C program closing when user has been inputed data other than using getch(). I do not like using it. In C++, you can do this:
Code:
cin.ignore();
getchar();
But cin is a C++ keyword. When i use getch I have to include conio.h with the program which is a bit of a waste for the purpose of 1 statement. Is there a command under the stdio,h header that can execute the same way getch() does in conio,h?
Example:
Code:
#include <stdio.h>
#include <conio.h> // this is annoying!
int main()
{
int num1, num2;
int sec = 0;
printf("Enter my first secret nunber: ");
scanf("%d", &num1);
printf("\nEnter my second secret number: ");
scanf("%d", &num2);
/* logical AND */
if (( num1 == 9 ) && ( num2 == 99 ))
{
printf("\nWELL DONE!");
sec = 5;
}
/* logical OR */
if (( num1 == 0 ) || ( num2 == 0 ))
{
printf("\nNone of the numbers are zero");
sec = 4;
}
/* logical NOT */
if ( !sec )
{
printf("\nSorry, both or either numbers are incorrect");
}
getch();
return 0;
}