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.However, 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.. 7 12749
"Zack Wahab" <ku******@hotmail.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.However, 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. ku******@hotmail.com (Zack Wahab) wrote in message news:<a0**************************@posting.google. 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.However, 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
"Arijit" <pa*****@yahoo.co.in> wrote in message
news:df*************************@posting.google.co m... ku******@hotmail.com (Zack Wahab) wrote in message
news:<a0**************************@posting.google. 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.However, 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
In message <pJ*******************@bgtnsc05-news.ops.worldnet.att.net>,
Howard <al*****@hotmail.com> writes "Arijit" <pa*****@yahoo.co.in> wrote in message news:df*************************@posting.google.c om...
[...] 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
Richard Herring <ju**@[127.0.0.1]> wrote in message news:<7Y**************@baesystems.com>... In message <pJ*******************@bgtnsc05-news.ops.worldnet.att.net>, Howard <al*****@hotmail.com> writes "Arijit" <pa*****@yahoo.co.in> wrote in message news:df*************************@posting.google.c om... [...]
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
In message <df***********************@posting.google.com>, Arijit
<pa*****@yahoo.co.in> writes Richard Herring <ju**@[127.0.0.1]> wrote in message news:<7Y**************@baesystems.com>... In message <pJ*******************@bgtnsc05-news.ops.worldnet.att.net>, Howard <al*****@hotmail.com> writes > >"Arijit" <pa*****@yahoo.co.in> wrote in message >news:df*************************@posting.google.c om... [...]
>> >> 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
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.However, 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.. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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 =...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |