-
Help with Dev C++!
I gots a prob. Whenever I run the program, the program pops up and then dissapears! Here's the code:
Code:
#include <iostream.h>
#include <string>
#include <windows.h>
int main()
{
std::string plant;
std::string glint;
cout << "The world is about to be destroyed. You are in a futuristic spy base." << endl;
cout << "You will soon go on a mission to save the world. In the corner of the room," << endl;
cout << "you see a plant. The door is to the north and the basement is down." << endl;
std::string firstroom;
cin >> firstroom;
if(firstroom == "x plant")
{
cout << "As you examine the plant, you spot a glint of silver in the soil." << endl;
cin >> plant;
}
if(plant == "x glint" || "get glint")
{
plant:
cout << "You pick up the glint. It is a keycard to the NETWORK." << endl;
int getglint;
getglint = 1;
cin >> glint;
}
system("pause");
return 0;
}
Yup
-
Start-->Run-->Cmd/Command--> C:\>YourProg.exe
-
thanks, but...
-
Everyone has this problem. iF you do a search you will find other solutions. i use this.
Code:
#include <conio.h> // include this header file
#include <iostream.h>
#include <string>
#include <windows.h>
int main()
{
std::string plant;
std::string glint;
cout << "The world is about to be destroyed. You are in a futuristic spy base." << endl;
cout << "You will soon go on a mission to save the world. In the corner of the room," << endl;
cout << "you see a plant. The door is to the north and the basement is down." << endl;
std::string firstroom;
cin >> firstroom;
if(firstroom == "x plant")
{
cout << "As you examine the plant, you spot a glint of silver in the soil." << endl;
cin >> plant;
}
if(plant == "x glint" || "get glint")
{
plant:
cout << "You pick up the glint. It is a keycard to the NETWORK." << endl;
int getglint;
getglint = 1;
cin >> glint;
}
getch();// add this line it, it waits for any keystroke from user!!!!
return 0;
}
Just add the header file and that getch() line in front of your return 0 and it should work. IF not look around and find other ways that people do it.
-
Actually, you don't need to use a not-standard function and library like getch() from conio. You just need to pause your program, a good way to do it is to add before the 'return' of your end function this snippet:
-
help!
now when i do it, it just says
Press any key
when i compile it.
-
He says "Press any key to continue..." and you should press any key to exit from the program.
-
right, but thats all it says and it doesn't run the actual program
-
Vber you are correct its not good to use non-standard. However if you look closely at his original program thats what he used. System pause and it didnt work thats why he is asking for help.
-
yes, but pause must be in all caps to work i believe. you could use std::cin.get(); before return; and if it doesn't work:
Code:
std::cin.ignore();
std::cin.get();
add these two lines before the return statement.
edit: gcn, try placing it after code, and before the return statement. if you did, and that is the output you get with the above mentioned methods, then that is weird. at that pt. you may want to post code again.
-
> yes, but pause must be in all caps to work i believe.
Actually that works just fine.
> Whenever I run the program, the program pops up and then dissapears! Here's the code:
That's very weird considering that your code asks for input almost immediately.
-
It doesn't have to be in caps. All system() does is send that string to the command line. It can be in mixed-case for all it cares.
-
>
It doesn't have to be in caps. All system() does is send that string to the command line. It can be in mixed-case for all it cares.
<
Thanks for echoing me. :)
-
#using namespace std
with your cin lines:
"firstroom"
"glint"
"plant"
These are declared as strings
'