A problem in an integer addition program in C

C, C++, Visual C++, C++.Net Topics
Post Reply
CAT77
Sergeant
Sergeant
Posts: 14
Joined: Fri Nov 15, 2013 8:18 pm

A problem in an integer addition program in C

Post by CAT77 » Mon Feb 17, 2014 6:19 pm

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
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: A problem in an integer addition program in C

Post by Neo » Tue Feb 18, 2014 7:58 pm

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.
Post Reply

Return to “C/C++ Programming”