My work is still jumping for a second and gone.

Started by
9 comments, last by Slyfox 15 years, 3 months ago
http://www.gamedev.net/community/forums/topic.asp?topic_id=487824 This person had the same problem as me, but it still doesnt work for me. #include <iostream.h> using namespace std; int main() { int score; double distance; char playAgain; bool shieldsup; short lives, aliensKilled; score = 0; distance = 1200.76; playAgain = `y'; shieldsUp = true; lives = 3; aliensKilled = 10; double engineTemp = 6572.89; cout << "\nscore: " << score << endl; cout << "distance: " << distance << endl; cout << "lives: " << lives << endl; cout << "aliensKilled: "<< aliensKilled << endl; cout << "engineTemp: " << engineTemp << endl; int fuel; cout << "\nHow much fuel? "; cin >> fuel; cout << "fuel: " << fuel << endl; typedef unsigned short int ushort; ushort bonus = 10; cout >> "\nbonus: " << bonus << endl; cout << "\nPress the Enter Button"; cin.ignore(cin.rdbuf()->in_avail() + 1); system("pause"); return 0; } It still flashes after the last command that was appointed in the other thread what am I doing wrong?
Advertisement
Quote:Original post by pven
It still flashes after the last command that was appointed in the other thread what am I doing wrong?


system("pause"); will only request you to press any key to continue. When you press the key, your program will shut down, because it ends. Is this the problem? If so, replace that with while(1) system("pause"); and your program will never shut down.

If you want window not to close after it ends, create a shortcut (place it to your desktop, for example), edit it's properties and check box with something like "Do not close window when program ends".
Do you mean like this?

while(1) system("pause");

Tested it out, the compiling works perfect but when i debug it still just flashes away. Tried the thing with the shortcut to didnt find it :/ Im using Vista x64 Ultimate..
This has been answered a million and a half times. Just run the program from the console, as it is meant to be (it's a console program, after all).

And on a side note, I suggest installing Microsoft's "Open Command Window Here" PowerTool, so that you can right-click on the debug folder and have a command prompt open to that directory.


system("PAUSE") only works on Windows, anyway.
Ezbez: Now I have tried to run it in cmd.exe but it still flashes away faster than I can blink.
I have used this solutions both in Microsoft Visual 2008 Studio and in the command promt and it still flashes away :/


cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);

cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);
system("pause");

system("pause");
cout << "Press the enter key to exit";
cin.ignore(std::cin.rdbuf()->in_avail() + 1);

system("pause");


while(1) system("pause");
cout << "\nPress the Enter Button";
cin.ignore(cin.rdbuf()->in_avail() + 1);

cout << "\nPress the Enter Button";
cin.ignore(cin.rdbuf()->in_avail() + 1);


All this combinations have been tried and i still dont get it to work.
This just makes no sense to me. What does "flashes away" mean? Can you be more descriptive?

while(1); should have your program looping forever. If it doesn't, call an exorcist.
Quote:Original post by Hollower
This just makes no sense to me. What does "flashes away" mean? Can you be more descriptive?

while(1); should have your program looping forever. If it doesn't, call an exorcist.


Or may I suggest a visit to your local debugger? Microsoft's Visual Studios Express Edition has quite a competent debugger.


As for the "flashes away" - huh? There's nothing to flash if you run it from the command line. It should just run the program and the show all output. If there's no output, it would go straight to the next command. No new window should be made, unless you're making one.
Flashes away means that the command prompt just pops up for like a millisecond, executes the command and then disappears so quickly that you don't even have time to see the output.


Something as simle as:

int n;
cin>>(n);


should make the command promt stay until the next time i press enter?
I have some suggestions.
Quote:Original post by pven
#include <iostream.h>

Should be:
#include <iostream>

Quote:Original post by pven
playAgain = `y';

You used a backquote/backtick/grave accent on the left side of the variable. It should be:
	playAgain = 'y';

This topic is closed to new replies.

Advertisement