Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Piranha13

How to wait for enter in c++

This topic is 5276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to port an old program for TI-basic to c++, to gain better experience with c++, and I''m having a problem with the TI''s pause function. Ive that using the system("PAUSE") is bad, but what other alternatives is there? Also, is there any way to clear the dos box, like the command cls?

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Piranha13
Ive that using the system("PAUSE") is bad, but what other alternatives is there?


loop, and wait until user presses Enter.

quote:

Also, is there any way to clear the dos box, like the command cls?

Turbo C++ has a command called clrscr() in conio.h, but this function is not available in Visual C++. One way to do it is to print blank lines until everything is shifted up by one screen.

Share this post


Link to post
Share on other sites
To clear the screen I found this.

To pause,I think this will work though I haven''t tested it.

//Thanks to Mike29936.
#include <stdio.h>

int main(void)
{
char var;
scanf("%c",&var);
return 0;
}


You will need to flush "var" out before utilizing it again because the function will read it and go on.

Share this post


Link to post
Share on other sites
quote:
Original post by Piranha13
Ive that using the system("PAUSE") is bad, but what other alternatives is there?

system("pause") is not bad, but it only works with windows/DOS. you could use other ways if you want, like a loop, or just use cin.get();

quote:
Original post by Piranha13
Also, is there any way to clear the dos box, like the command cls?

for windows/DOS, you can use system("cls");

(EditExample

#include <iostream>
using namespace std;

int main() {
for(int i=0;i<10;i++)
cout << "\nHi there!\n";
cout << "\nPress Enter to clear the screen." << endl;
cin.get();
system("cls");
cout << "ta-dah!!! :-)\n" << endl;
cout << "now i'll pause" << endl;
system("pause");
return 0;
}


VRAM Strider.

[edited by - VStrider on June 6, 2004 10:46:01 PM]

Share this post


Link to post
Share on other sites
use this man:

cout << "Press Enter To Continue";
getchar();



[edited by - nervo on June 6, 2004 12:04:04 AM]

Share this post


Link to post
Share on other sites
Well, the getchar() method dosnt work on everything...It works somewhat...but here is a problem spot I'm having:

while (clownLife > 1)
{
clownLife = clownLife - 1;
system("CLS");
cout << "\nMoves List:\n";
cout << "-----------\n";
cout << "1 - Poke Eye\n";
cout << "2 - Smack head\n";
cout << "3 - Throw dog food\n";
cout << "4 - Pull hair\n";
cout << "5 - Yell in ear\n";
cout << "6 - Step on foot\n";
cout << "-----------\n";
cin >> choice;
random = rand() % 100;

cout << "\n\nClowns life meter: " << clownLife << ".\n";



if (random > 80)
{
cout << "The clown screams, turns around 6 times and spits in his pants";
getchar();
continue;
}



Now the problem is, it seems to take the enter from cin >> choice, and skipping the getchar()

[edited by - piranha13 on June 7, 2004 4:10:54 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Piranha13
Hmm...maybe I should have said I am using Dev-C++....

err...the code compiles fine with Dev-C++. i tried it before i post it. what exactly is the problem?

VStrider.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!