Page 1 of 1

A problem in an integer addition program in C

Posted: Mon Feb 17, 2014 6:19 pm
by CAT77
This is about a problem I encountered while trying to write an addition programm in C.
I will enclose every single detail happened inorder to make it easy for you, who are here in this forum, to understand where the actual error is.
IDE- CodeBlocks
Compiler- GNU GCC C compiler
OS- Windows 7 Home Premium 64bit
Below is the Source Code

Code: Select all

/*Integer addition Program*/
#include <stdio.h>
int main (void)
{
int integer1; 
int integer2;
int sum;

printf("Enter First integer\n");
scanf("%d", &integer1);

printf("Enter Second Integer\n");
scanf("%d", & integer2);

sum = integer1+ integer2;

printf("Sum is %d \n", sum);

return 0;
}

When it is built and run within Code::Blocks it works perfectly but when I try to open it from the file where I saved it does not work properly.
It works up to taking the two integers as inputs and when I press the enter key the window suddenly disappears. This happens to every program that is written in this IDE in this computer.
Where can be the problem might be? :shock: :shock: :? :? Thanks in Advance

Re: A problem in an integer addition program in C

Posted: Tue Feb 18, 2014 7:58 pm
by Neo
There is nothing wrong in the behaviour. The program ends with return so the program exit. You better open a command prompt and run your console program from there. So you would see the console output and get yourself back to command prompts after execution.