Window Console Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 8
Reputation: .·)Tusky(·. is an unknown quantity at this point 
Solved Threads: 0
.·)Tusky(·.'s Avatar
.·)Tusky(·. .·)Tusky(·. is offline Offline
Newbie Poster

Window Console Help

 
0
  #1
Jul 25th, 2004
I'm using the Window Console to create a excerice out of a book for beginers. First it's coded to ask for a number, then after you press the enter key it tells you the results, in about 2 seconds it just closes the Window Console. How can I prevent the Window Console from closeing? I'll give you the code below.

#include <iostream>
using namespace std;

double Cube (double Value);

main ()
{
double Number, CubeNumber;

cout << "Enter a number: ";
cin >> Number;

CubeNumber = Cube (Number);

cout << CubeNumber << endl;

return 0;
}

double Cube (double Value)
{
double CubeReturn;

CubeReturn = Value * Value * Value;

return CubeReturn;
}

"But I'm not a slave to a god that doesn't exist
But I'm not a slave to world that doesn't give a S•••" - Marilyn Manson (The Fight Song)
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Window Console Help

 
0
  #2
Jul 26th, 2004
Easy enough ,

Include conio.h and put a getch() before return 0; in main().getch() waits for the user to press a key and it returns that value.

So
  1.  
  2. char ch;
  3.  
  4. ch = getch();
  5.  
  6. cout<<"User Pressed :"<<ch<<" Int value:"<<(int)ch;

So if the user pressed enter the int value is 13, if it is 'A' the int value is 64 i.e the ascii values of the key pressed.

Helps?
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 95
Reputation: omol is an unknown quantity at this point 
Solved Threads: 4
omol's Avatar
omol omol is offline Offline
Junior Poster in Training

Re: Window Console Help

 
0
  #3
Jul 26th, 2004
you could use a while loop or if your using m$ use cmd to open the exe

but any ways the while loop for ya

#include <iostream>
using namespace std;

double Cube (double Value);

main ()
{
char quit; //declare a char variable char
while (quit != 'q') //the while loop
{
double Number, CubeNumber;

cout << "Enter a number: ";
cin >> Number;

CubeNumber = Cube (Number);

cout << CubeNumber << endl;
cout << "\nPress q to quit\n";
cin>>quit; //when q is entered the program will exit
}
return 0;
}

double Cube (double Value)
{
double CubeReturn;

CubeReturn = Value * Value * Value;

return CubeReturn;
}

Think this is what your after but i would recomend using the cmd method intill you get used to loops and the way they work.
asm
{ "\x04f\x06d\x06f\x06c" }
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 3
Reputation: diablo is an unknown quantity at this point 
Solved Threads: 0
diablo diablo is offline Offline
Newbie Poster

Re: Window Console Help

 
0
  #4
Jul 27th, 2004
Well, you could just add this to the last line :
system("Pause") ;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC