| | |
Window Console Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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;
}
#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)
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
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?
,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
C++ Syntax (Toggle Plain Text)
char ch; ch = getch(); 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?
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.
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" }
{ "\x04f\x06d\x06f\x06c" }
![]() |
Similar Threads
- starting a new window without console (C#)
- Console GDI (C++)
- Please help!!! Winsock2/Sockets with C++ Console app? (C++)
- Destroy/Close the window (C++)
- Clear the console screen (Java)
- How to make the command window not come up while running an .exe (C++)
Other Threads in the C++ Forum
- Previous Thread: Text File Input and manipulation
- Next Thread: scanf - compiles but causes error
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





