C++ Program to add two numbers

Hi,

I am trying to execute the below addition of two numbers C++ Program using Dev C++ IDE.. and am not getting the output.

As I looked into the code there seems to be no problem. Please help me.

What happens is when I enter two numbers in the command prompt after the execution of program I dont get output and it just disappears without any output.

//program to add two numbers

#include<iostream>

using namespace std;
main()
{
int a,b,c;
cout<<"Enter two numbers"<<endl;
cin>>a>>b;
c=a+b;
cout<<"Sum of two numbers are"<<c;
cout<<c<<endl;
}
I think you can add system("pause"); after the cout<<c<<endl;
Yes, it is working
Thanks a lot

But why like that it happens?
Pause will hold cmd prompt till we press an enter.

Am I right?
Yes, it will ask the system to pause first before it closes :)
Ok thanks :)
simple use getch();
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include <conio.h>
using namespace std;
main()
{
int a,b,c;
cout<<"Enter two numbers"<<endl;
cin>>a>>b;
c=a+b;
cout<<"Sum of two numbers are"<<c;
cout<<c<<endl;
getch();
}
But why like that it happens?
Pause will hold cmd prompt till we press an enter


about system("pause");

system() throws commands at the command prompt or terminal,

just like you can (in windows)mkdir, cls, cd, del, dir....(or in linux)mkdir,clear,cd,rm,pwd,ls..etc , you can use system() to do this within a program..

in windows, open up your cmd prompt and type "pause" and you should understand better why system("pause") does what it does..

(i think pause is used for batch scripting, but i don't really know...)
Last edited on
Topic archived. No new replies allowed.