473,789 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple addition program, no output

Hi,

I use Dev C++ compiler. Tried this program :

// Fig. 1.6: fig01_06.cpp
// Addition program.
#include <iostream>

// function main begins program execution
int main()
{
int integer1; // first number to be input by user
int integer2; // second number to be input by user
int sum; // variable in which sum will be stored

std::cout << "Enter first integer\n"; // prompt
std::cin >> integer1; // read an integer

std::cout << "Enter second integer\n"; // prompt
std::cin >> integer2; // read an integer

sum = integer1 + integer2; // assign result to sum

std::cout << "Sum is " << sum << std::endl; // print sum
// indicate that program ended successfully
} // end function

The window prompt to enter the integers.Howeve r, the result was not
displayed. Instead, immediately it comes back to the compiler program
(The command Prompt window immediately turn off). Is it something to
do with the compiler? I tried to find the button for enabling output
result but couldn't find one..
Jul 22 '05 #1
7 12774
"Zack Wahab" <ku******@hotma il.com> wrote...
I use Dev C++ compiler. Tried this program :

// Fig. 1.6: fig01_06.cpp
// Addition program.
[...]
The window prompt to enter the integers.Howeve r, the result was not
displayed. Instead, immediately it comes back to the compiler program
(The command Prompt window immediately turn off). Is it something to
do with the compiler? I tried to find the button for enabling output
result but couldn't find one..


Get out of the IDE and run your program from the command line.
Jul 22 '05 #2
ku******@hotmai l.com (Zack Wahab) wrote in message news:<a0******* *************** ****@posting.go ogle.com>...
Hi,

I use Dev C++ compiler. Tried this program :

// Fig. 1.6: fig01_06.cpp
// Addition program.
#include <iostream>

// function main begins program execution
int main()
{
int integer1; // first number to be input by user
int integer2; // second number to be input by user
int sum; // variable in which sum will be stored

std::cout << "Enter first integer\n"; // prompt
std::cin >> integer1; // read an integer

std::cout << "Enter second integer\n"; // prompt
std::cin >> integer2; // read an integer

sum = integer1 + integer2; // assign result to sum

std::cout << "Sum is " << sum << std::endl; // print sum
// indicate that program ended successfully
} // end function

The window prompt to enter the integers.Howeve r, the result was not
displayed. Instead, immediately it comes back to the compiler program
(The command Prompt window immediately turn off). Is it something to
do with the compiler? I tried to find the button for enabling output
result but couldn't find one..

At the very end of the program write
int main()
{
........
........ //your program

int dummy;
cin >> dummy;

return 0; // optional
}

This will keep the command prompt open until you enter a dummy
value at the end.

-Arijit
Jul 22 '05 #3

"Arijit" <pa*****@yahoo. co.in> wrote in message
news:df******** *************** **@posting.goog le.com...
ku******@hotmai l.com (Zack Wahab) wrote in message

news:<a0******* *************** ****@posting.go ogle.com>...
Hi,

I use Dev C++ compiler. Tried this program :

// Fig. 1.6: fig01_06.cpp
// Addition program.
#include <iostream>

// function main begins program execution
int main()
{
int integer1; // first number to be input by user
int integer2; // second number to be input by user
int sum; // variable in which sum will be stored

std::cout << "Enter first integer\n"; // prompt
std::cin >> integer1; // read an integer

std::cout << "Enter second integer\n"; // prompt
std::cin >> integer2; // read an integer

sum = integer1 + integer2; // assign result to sum

std::cout << "Sum is " << sum << std::endl; // print sum
// indicate that program ended successfully
} // end function

The window prompt to enter the integers.Howeve r, the result was not
displayed. Instead, immediately it comes back to the compiler program
(The command Prompt window immediately turn off). Is it something to
do with the compiler? I tried to find the button for enabling output
result but couldn't find one..

At the very end of the program write
int main()
{
.......
....... //your program

int dummy;
cin >> dummy;

return 0; // optional
}

This will keep the command prompt open until you enter a dummy
value at the end.


It might be better to stream into a string than an int. Using an integer,
if the user fails to enter a valid integer, the program will not be happy.

-Howard
Jul 22 '05 #4
In message <pJ************ *******@bgtnsc0 5-news.ops.worldn et.att.net>,
Howard <al*****@hotmai l.com> writes

"Arijit" <pa*****@yahoo. co.in> wrote in message
news:df******* *************** ***@posting.goo gle.com...


[...]

At the very end of the program write
int main()
{
.......
....... //your program

int dummy;
cin >> dummy;

return 0; // optional
}

This will keep the command prompt open until you enter a dummy
value at the end.


It might be better to stream into a string than an int. Using an integer,
if the user fails to enter a valid integer, the program will not be happy.


.... indeed, it will be so unhappy that it will set the failbit on
std::cin. That may be a price the OP is prepared to pay.

Whereas, reading a string, it has the potential to run out of memory.

--
Richard Herring
Jul 22 '05 #5
Richard Herring <ju**@[127.0.0.1]> wrote in message news:<7Y******* *******@baesyst ems.com>...
In message <pJ************ *******@bgtnsc0 5-news.ops.worldn et.att.net>,
Howard <al*****@hotmai l.com> writes

"Arijit" <pa*****@yahoo. co.in> wrote in message
news:df******* *************** ***@posting.goo gle.com...
[...]

At the very end of the program write
int main()
{
.......
....... //your program

int dummy;
cin >> dummy;

return 0; // optional
}

This will keep the command prompt open until you enter a dummy
value at the end.


It might be better to stream into a string than an int. Using an integer,
if the user fails to enter a valid integer, the program will not be happy.


But if OP is not using a string in his program, he must #include
<string> just for this purpose. Why include an unnecessary header.
... indeed, it will be so unhappy that it will set the failbit on
std::cin. That may be a price the OP is prepared to pay.
Its the last line of the program. Setting failbit shouldn't matter,
unless in some destructor cin is used (very unlikely taking input in
destructor).
Whereas, reading a string, it has the potential to run out of memory.


_Extremely_ unlikely. Whats he going to type at the prompt, an essay
on how to terminate a program, that too without spaces ?

-Arijit
Jul 22 '05 #6
In message <df************ ***********@pos ting.google.com >, Arijit
<pa*****@yahoo. co.in> writes
Richard Herring <ju**@[127.0.0.1]> wrote in message
news:<7Y****** ********@baesys tems.com>...
In message <pJ************ *******@bgtnsc0 5-news.ops.worldn et.att.net>,
Howard <al*****@hotmai l.com> writes
>
>"Arijit" <pa*****@yahoo. co.in> wrote in message
>news:df******* *************** ***@posting.goo gle.com...
[...]
>>
>> At the very end of the program write
>>
>>
>> int main()
>> {
>> .......
>> ....... //your program
>>
>> int dummy;
>> cin >> dummy;
>>
>> return 0; // optional
>> }
>>
>> This will keep the command prompt open until you enter a dummy
>> value at the end.
>>
>
>It might be better to stream into a string than an int. Using an integer,
>if the user fails to enter a valid integer, the program will not be happy.


But if OP is not using a string in his program, he must #include
<string> just for this purpose. Why include an unnecessary header.
... indeed, it will be so unhappy that it will set the failbit on
std::cin. That may be a price the OP is prepared to pay.

Its the last line of the program. Setting failbit shouldn't matter,
unless in some destructor cin is used (very unlikely taking input in
destructor).


Exactly.
Whereas, reading a string, it has the potential to run out of memory.


_Extremely_ unlikely. Whats he going to type at the prompt, an essay
on how to terminate a program, that too without spaces ?

ISTR some versions of Unix included a program called 'yes' which output
an infinite string of 'Y's. You could pipe its output to stupid programs
which insisted on user confirmation of every action.

--
Richard Herring
Jul 22 '05 #7
In Dev C++ there must be a Output Window

Anil Mamede
Zack Wahab wrote:
Hi,

I use Dev C++ compiler. Tried this program :

// Fig. 1.6: fig01_06.cpp
// Addition program.
#include <iostream>

// function main begins program execution
int main()
{
int integer1; // first number to be input by user
int integer2; // second number to be input by user
int sum; // variable in which sum will be stored

std::cout << "Enter first integer\n"; // prompt
std::cin >> integer1; // read an integer

std::cout << "Enter second integer\n"; // prompt
std::cin >> integer2; // read an integer

sum = integer1 + integer2; // assign result to sum

std::cout << "Sum is " << sum << std::endl; // print sum
// indicate that program ended successfully
} // end function

The window prompt to enter the integers.Howeve r, the result was not
displayed. Instead, immediately it comes back to the compiler program
(The command Prompt window immediately turn off). Is it something to
do with the compiler? I tried to find the button for enabling output
result but couldn't find one..

Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3547
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
17
6525
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual interest rate I, and annual service charge S. Your algorithm would then compute and print out the total amount of interest earned during the year and the final account balance at the end of the year (assuming that interest is compounded monthly, and...
19
2989
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
4
3286
by: allenevaalleneva | last post by:
Q:Write a program that prints the numbers 1 to 4 on the same line with with each pair of adjacent numbers separated by one space. Do this several ways: a) Using one statement with one stream insertion operator. b) Using one statement with four stream insertion operators. c) Using for statement my answers are as follow a)
5
4596
by: Mike | last post by:
Hello All, Please, if anyone can point me to the problem, I'd sure appreciate it! I am very new to VB programming and not a programmer to begin with. This is part of a Visual Basic 2005 Express Edition program to control a remote basketball scoreboard display unit. All I'm trying to do is add 5 byte variables and store the result in an integer variable. I added a Try/Catch block to take look at things. This exception occurs only when...
1
2942
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can anyone help me on this please. and also during the operation selection, if ill enter a character it wont go back to the main program. by the way, my compiler is Dev-C++. I need help badly..here's my code below... #include <iostream.h> #include...
5
1524
by: wazzup | last post by:
My task is Create a program to read a simple integer expression and display the result. "Simple" means no parentheses are allowed and only the +, -, *, and / operators are allowed. I think expression would be Multiplications, then Division, then Addition and Subtraction. My program gave me a wrong result after addition, take a look to my code you will understand. Please help me to develop this. Here is my Code
8
1556
by: ianenis.tiryaki | last post by:
well i wrote this code but it doesn't work and shows me bunch of syntax if you can help me out finding them i would appreciate it! the program should do simple calculations and no parenthesis are allowed.so it is basically really simple but i am new at programming and not sure about my code. Thank you! here is my code: #include <iostream>
1
6025
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main function which i think has problem // this a simple program about phonebook,it can add items,del items,find items and #include "member.h" #include <fstream> #include <vector>
0
9659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9504
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10400
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9977
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9011
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5413
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5545
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2903
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.