Page 1 of 1
[SOLVED] Console application question
Posted: Sun Jul 18, 2010 1:09 am
by Kyosaur
I decided to take up c++ and make a simple console game. Im just wondering if there is a way to stop the console from closing until i call a certain function (maybe OnGameModeEnd) ? I know of system("pause"); but its not exactly what im looking for.
Re: Console application question
Posted: Sun Jul 18, 2010 1:44 am
by zeid
Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h>
void main()
{
bool exit=false;
while(!exit)
{
if(kbhit())
if(getch()=='q')
exit=true;
}
}
Re: Console application question
Posted: Sun Jul 18, 2010 1:50 am
by Kyosaur
zeid wrote:Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h>
void main()
{
bool exit=false;
while(!exit)
{
if(kbhit())
if(getch()=='q')
exit=true;
}
}
Ohh nice, thanks.
EDIT: Is there a way to make it accept input? Kind of hard to make a text based game if you cant input anything D:.
Re: Console application question
Posted: Sun Jul 18, 2010 2:08 am
by X Abstract X
Kyosaur wrote:zeid wrote:Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h>
void main()
{
bool exit=false;
while(!exit)
{
if(kbhit())
if(getch()=='q')
exit=true;
}
}
Ohh nice, thanks.
EDIT: Is there a way to make it accept input? Kind of hard to make a text based game if you cant input anything D:.
The example zeid posted does take in input. All you have to do is store it in a string. You might want to use std::cin though, it's standard C++.
Code: Select all
std::string input;
std::cout << "Enter your name.\n";
std::cin >> input;
std::cout << "Your name is: " << input << ".\n";
Re: Console application question
Posted: Sun Jul 18, 2010 2:18 am
by Kyosaur
X Abstract X wrote:Kyosaur wrote:zeid wrote:Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h>
void main()
{
bool exit=false;
while(!exit)
{
if(kbhit())
if(getch()=='q')
exit=true;
}
}
Ohh nice, thanks.
EDIT: Is there a way to make it accept input? Kind of hard to make a text based game if you cant input anything D:.
The example zeid posted does take in input. All you have to do is store it in a string. You might want to use std::cin though, it's standard C++.
Code: Select all
std::string input;
std::cout << "Enter your name.\n";
std::cin >> input;
std::cout << "Your name is: " << input << ".\n";
Thanks, thats exactly what i was looking for :D.
Sorry for the n00by question lol, im still learning
.
Re: Console application question
Posted: Sun Jul 18, 2010 2:24 am
by X Abstract X
Everyone's been there, don't be afraid to ask anything.
Re: Console application question
Posted: Sun Jul 18, 2010 2:29 am
by Kyosaur
X Abstract X wrote:Everyone's been there, don't be afraid to ask anything.
ok lol.
going to add solved to the tittle now, thanks again for the help guys :D.