Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-17-2001, 03:37 PM   #1
Member (9 bit)
 
ironzombie99's Avatar
 
Join Date: Jul 2001
Posts: 355
Help

I just started out playing around with C++ today.
Anyway after i compile the code and run it, the dos prompt comes up and shows it for only about 1-2 seconds, what do i do to make it stay longer?

Hers my simple code

#include
#include

int main()
{
cout << "My name is Nick" << endl;
int myage = 15;
cout << "My age is" << myage << endl;
cout << "The date is" < cout << "11/17/01" < return 0;

}
ironzombie99 is offline   Reply With Quote
Old 11-17-2001, 03:38 PM   #2
Member (9 bit)
 
ironzombie99's Avatar
 
Join Date: Jul 2001
Posts: 355
Im using Dev-C++ 4 to do this
ironzombie99 is offline   Reply With Quote
Old 11-17-2001, 03:59 PM   #3
Member (13 bit)
 
DrZaius's Avatar
 
Join Date: Jul 2000
Location: Fullerton, CA
Posts: 7,030
Hi ironzombie99,

You need to ask for user input so that the program will pause and you can see the results. Try this for example:

Code:
#include 

int main()
{
  int age;
  cout << "Please enter your age:";
  cin >> age;
  cout << "Your age is: " << age;
  return 0;
}
__________________
"A witty saying proves nothing." - Voltaire
DrZaius is offline   Reply With Quote
Old 11-17-2001, 04:04 PM   #4
Member (9 bit)
 
ironzombie99's Avatar
 
Join Date: Jul 2001
Posts: 355
thanks ill try this out
ironzombie99 is offline   Reply With Quote
Old 11-17-2001, 11:24 PM   #5
Member (9 bit)
 
Join Date: Sep 2000
Location: Douglas, GA
Posts: 302
Send a message via ICQ to Leef
Rather than clicking on the .exe to run it...run it from a DOS prompt instead. I had to do this when I was trying to learn C++. Basically...when the program runs...it shuts down the prompt when the program finishes. But if you run it from within the DOS prompt, it shouldn't shut it down.
Leef is offline   Reply With Quote
Old 11-19-2001, 04:04 AM   #6
Member (7 bit)
 
kcbhiw's Avatar
 
Join Date: May 2000
Location: Atlanta, Georgia
Posts: 95
you need to break the screen

try adding either cin.get(1); or getch(); to your code. Like this:

#include
#include

int main()
{
cout << "My name is Nick" << endl;
int myage = 15;
cout << "My age is" << myage << endl;
cout << "The date is" < cout << "11/17/01" < return 0;
cin.get(1);
}

or

#include
#include

int main()
{
cout << "My name is Nick" << endl;
int myage = 15;
cout << "My age is" << myage << endl;
cout << "The date is" < cout << "11/17/01" < return 0;
getch();
}

that will pause the screen and require you to press enter.

requesting an input, such as 'cin' will not stop the screen to allow you to view the final output. it will only allow you to read the output up until the 'cin' statement. if using cin, and cin.ignore();, you will have two screen stops. try this out if u want to load 'myage' manually:

#include
#include

int main()
{
cout << "My name is Nick" << endl;
cin >> myage;
cout << "My age is" << myage << endl;
cout << "The date is" < cout << "11/17/01" < return 0;
cin.get(1);
}


the '1' in cin.get(), for sake of simplicity, ignores the enter key.
hope this helps.
kcbhiw is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:43 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2