By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

Wat is wrong wif this very short code?? Please help

P: 1
The code looks like this (got this from dev++ C tutorial):

#include <stdio.h>

main ()
{
int num1, num2;

printf("\nEnter first number ");
scanf("%d",&num1);

printf("\nEnter second number ");
scanf("%d",&num2);

if (num2 ==0) printf("\n\nCannot devide by zero\n\n");
else printf("\n\nAnswer is %d\n\n",num1/num2);

}

The problem is after the prog prompt me for the second no, and after I entering and hitting the 'Enter' key, the whole this disappears - failing to print either the statements, "Cannot devide by zero" or "Answer is...".

Tried different compiler like Borland and also replacing scanf with getchar - and still get the same thing. Wat is wrong???

Thanks a zillion for your help.
May 23 '06 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,949
I suspect the problem is the way you are running it. This is a console(command line) application and if you run it directly from Windows then a new console will be created for the application to run in. However once the program has finished the consoe lis no longer needed so Windows removes it and you don't get to see you results.

I suggest that you manually start a console (cmd.exe) and run you application there, in this case because the console was not created specifically to run the app in Windows does not remove the console when the app finishes leaving the results on screen.
May 23 '06 #2

P: 16
or just add an extra scanf("%d",&num2);
or getch(); to the end so that it waits for some kind of input...
Jun 13 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.