473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Window closes immediately after execution.

k, so here's the problem: this is the code i've written:


#include <iostream>
using namespace std;

int main()

{
int length, width;

cout << "Enter the length: ";
cin >> length;

cout << "Enter the width: ";
cin >> width;

cout << "The area is " << length * width;

return 0;
}

But it's probably not even my code since this works for anything i write.
When i compile and run this file in Dev C++, i can enter the first two digits no problem, but when i hit enter after that, it doesnt display my area, or it might but, the windows closes instantly.

Anyone know how to fix this, is it simply some settings or...
Mar 22 '07 #1
1 2004
sicarie
4,677 Expert Mod 4TB
k, so here's the problem: this is the code i've written:


#include <iostream>
using namespace std;

int main()

{
int length, width;

cout << "Enter the length: ";
cin >> length;

cout << "Enter the width: ";
cin >> width;

cout << "The area is " << length * width;

return 0;
}

But it's probably not even my code since this works for anything i write.
When i compile and run this file in Dev C++, i can enter the first two digits no problem, but when i hit enter after that, it doesnt display my area, or it might but, the windows closes instantly.

Anyone know how to fix this, is it simply some settings or...
Yes, if you're running it in the console, there is nothing to keep the window open. The answer is being displayed, just not fast enough for you to catch.

The simple solution is to put a cin statement at the end, so it will cin a var, but not matter (no calculations made on it) - this is the "Press Enter key to continue".

Also, code tags make your code more readable, and are appreciated. Thanks!

(Welcome to theScripts!)
Mar 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vetrivel | last post by:
Application architecture : Develop interface between two existing systems, a. Enterprise CRM system b. Web based intranet system. Environment : Intranet Server : IIS and ASP. Script :...
4
by: John H. | last post by:
Hello I have some trouble in closing a window, Here is the problem: I develop a asp.net website use client side valiation <asp:CustomValidator id="CustomValidator1"...
2
by: Seth E Seligman | last post by:
I'm working on a web based file manager. The rename file function creates a new window with a form allowing the user to enter a new file name. Before the form gets submitted, I want to make sure that...
14
by: Nigel Mercier ® | last post by:
I'm just starting to learn JavaScript, so far I like it! I want to add some JS to my Ebay listings, to manually open a pop-up window. It works OK, but the JS gets rejected by Ebay. If I can't...
10
by: Roland | last post by:
Hello, the example code is the following(the number in parentheses at the beginning are just for reference)(The complete HTML file is at the end of this article): (1)window.location =...
3
by: Steve Wark | last post by:
I have created a ASP.NET application and created two forms within the application (Webform1.aspx & Webform2.aspx). On the first form I have placed a textbox (TextBox1) and a button, which when...
0
by: Tharpa Roberts | last post by:
Under Visual C++ 6.0, if you made a command-line program, it would stay open after execution, and then you would press any key to close it. Under Visual Studio 2005, if you make a C++ command...
4
by: Eddie | last post by:
I am opening a windows (well, technically a greybox() call GB_show() which shows a nicer window than normal), and want to wait until that window is closed before moving to the next command. ...
5
by: prads | last post by:
Hello, Though I have given getchar(); at the end of my C++ program, it displays the output but the cmd window just flashes and closes immediately. It is a huge pgm of abt 500+ lines and deals with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.