473,462 Members | 1,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C++ Program Execution

Hello,

I have been getting to know C and C++ alot lately and have come up with
the same problem with each program that I write. When I compile the
program, it comes out with no errors. I can solve those no problem
(usually just a misplaced semicolon) but when it comes to executing the
program to verify my program works correctly, after I input one or
sometimes two variables it closes the window that it is running in. I
have tried using both Visual Studio 2003 and Dev-C++ to compile and run
the programs and it does the same thing in each. Anyone have an ideas
as to why this is happening? I will include code for one that I am just
starting off writing in this post to help you see what is writen.
Thanks in advance for all help recieved.

David

// Code Start:
#include <iostream>

int main()
{
char name;
int age = 0;

std::cout << "Enter your name: ";
std::cin >> name;
std::cout << "Enter your age: ";
std::cin >> age;
std::cout << "\nName: ";
std::cout << name;
std::cout << "\nAge: ";
std::cout << age;
}
// End Code

Oct 20 '05 #1
3 2825
<Al***************@gmail.com> wrote:

I have been getting to know C and C++ alot lately and have come up with
the same problem with each program that I write. When I compile the
program, it comes out with no errors. I can solve those no problem
(usually just a misplaced semicolon) but when it comes to executing the
program to verify my program works correctly, after I input one or
sometimes two variables it closes the window that it is running in. I
have tried using both Visual Studio 2003 and Dev-C++ to compile and run
the programs and it does the same thing in each. Anyone have an ideas
as to why this is happening? I will include code for one that I am just
starting off writing in this post to help you see what is writen.
Thanks in advance for all help recieved.

David

// Code Start:
#include <iostream>

int main()
{
char name;
int age = 0;

std::cout << "Enter your name: ";
std::cin >> name;
std::cout << "Enter your age: ";
std::cin >> age;
std::cout << "\nName: ";
std::cout << name;
std::cout << "\nAge: ";
std::cout << age;
}
// End Code


Try adding this just before the closing brace in main.

cin.get();
Oct 20 '05 #2
On Thu, 20 Oct 2005 14:37:52 -0700, Al***************@gmail.com wrote:
Hello,

I have been getting to know C and C++ alot lately and have come up with
the same problem with each program that I write. When I compile the
program, it comes out with no errors. I can solve those no problem
(usually just a misplaced semicolon) but when it comes to executing the
program to verify my program works correctly, after I input one or
sometimes two variables it closes the window that it is running in. I
have tried using both Visual Studio 2003 and Dev-C++ to compile and run
the programs and it does the same thing in each. Anyone have an ideas
as to why this is happening? I will include code for one that I am just
starting off writing in this post to help you see what is writen.
Thanks in advance for all help recieved.


If you're debugging it: set a breakpoint on the close brace of main.
If you're not debugging it: run from a separate command window.

- Jay

Oct 20 '05 #3
Al***************@gmail.com wrote:
Hello,

I have been getting to know C and C++ alot lately and have come up with
the same problem with each program that I write. When I compile the
program, it comes out with no errors. I can solve those no problem
(usually just a misplaced semicolon) but when it comes to executing the
program to verify my program works correctly, after I input one or
sometimes two variables it closes the window that it is running in. I
have tried using both Visual Studio 2003 and Dev-C++ to compile and run
the programs and it does the same thing in each. Anyone have an ideas
as to why this is happening? I will include code for one that I am just
starting off writing in this post to help you see what is writen.
Thanks in advance for all help recieved.

David

// Code Start:
#include <iostream>

int main()
{
char name;
int age = 0;

std::cout << "Enter your name: ";
std::cin >> name;
std::cout << "Enter your age: ";
std::cin >> age;
std::cout << "\nName: ";
std::cout << name;
std::cout << "\nAge: ";
std::cout << age; std::cout << std::endl;
cin.get(); }
// End Code

Oct 20 '05 #4

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

Similar topics

4
by: Bruce W...1 | last post by:
A scripting newbie question... I'm trying to understand some code I found. This script conducts a poll and writes the results to a text file. The following statement is part of the source file. ...
3
by: Daragoth | last post by:
Hi, I'm writing a program using Metrowerks CodeWarrior 4.0 that determines the best possible combination of a data set by checking every possible combination. I found there were about 250,000,000...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
1
by: Eric M | last post by:
Hi, I am new to c++ programming with Windows and I need to know if its possible to close applications or delay their execution from a seperate program. Ideally, I would want to pause the...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
12
by: Thomas Carter | last post by:
Is it possible, in an OS-independent way, to suspend a C program for some specified amount of time, in such a way that CPU load, due to this program, while remaining suspended, is non-existant or,...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
12
by: greg | last post by:
Hi, Can anyone help me with the following issue: How can I pause the execution of a program until a given file is created (by another process) in a specified directory? Any ideas would be...
4
by: sulekhasweety | last post by:
Hi, can any one give a brief outline of the different stages in the execution of a C program , in terms of compilation, pre-processing, linking etc
0
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...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.