| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
i got a problem
this is probably i easy little problem but i cant fix it so i was trying to make this (what they call game) but when i run and when i type the name it closes
so here is the code Code:
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
const int GOLD_PIECES = 900;
int adventurers, killed, survivors;
string leader;
cout<<"Welcome to Lost Fortune\n\n";
cout<<"Please enter the following for your personlized
adventure\n";
cout<<"Enter a number: ";
cin>>adventurers;
cout<<"Enter a number, smaller than the first: ";
cin>> killed;
survivors = adventurers - killed;
cout<<"Enter your last name: ";
cin>>leader;
cout<<"\nA brave gruop of "<<adventurers<<"set out on a quest
";
cout<<"-- in search of the lost treasure of the Ancient
Dwares. ";
cout<<"The group was led by the lengendary rogue,
"<<leader<<".\n";
cout<<"\nAlong the way, a band of marauding ogres ambushed
the party. ";
cout<<"All fought barely under the command of "<<leader;
cout<<", and the orges were defeated, but at a cost. ";
cout<<"Of the adventurers, "<<killed<<" were vanquished, ";
cout<<"leaving just "<<survivors<<" in group.\n";
cout<<"\nThe party was about to give up all hope. ";
cout<<"But while laying the decreased to rest. ";
cout<<"they stumbled upon the buried fortune. ";
cout<<"So they spilt "<<GOLD_PIECES<<" gold pieces.";
cout<<leader<<" held on the extra "<< (GOLD_PIECES %
survivors);
cout<<" pieces to keep things fair of course.\n";
return 0;
}
so yeah if u guys can get this runnin ill be happy ![]() and i already tried to do the cin.ingore thing and it wont work Last edited by B-Con : July 23rd, 2005 at 03:59 AM. Reason: added ending code tags to this post and the next one |
|
#2
|
|||
|
|||
|
k so i wont start another new thread here is another problem i got
here is my code Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"\tGame Designer's Network\n";
int security = 0;
string username;
cout<<"\nUsername: ";
cin>> username;
string password;
cout<<"Password: ";
cin>> password;
if (username == "S.Meier" && password == "civilization")
{
cout<<"\nHey, Sid.";
security = 5;
}
if (username == "S.Miyamoto" && password == "mariobros")
{
cout<<"\nWhat's up, Shigeru?";
security = 5;
}
if (username == "W.Wright" && password == "thesims")
{
cout<<"\nHow goes it, Will?";
security = 5;
}
if (username == "guest" || password == "guest")
{
cout<<"\nWelcome, guest.";
security = 1;
}
if (!security)
cout<<"\nYour login failed";
cin.ignore();
}
k but here is my problem after u run it and put username and password and closes!!!! and doestn do anything it just closes i am mad cause i got this source code from a bool that says its right! Which its not! plz help probably i can fix these 2 problems |
|
#3
|
||||
|
||||
|
Both programs have the same problem: you simply have nothing to pause the program before it closes. "cin.ignore()" just deals with cleaning out the keyboard buffer, it doesn't actually pause the program. Add a "cin.get()" line before the final "return" statement to pause the program to wait for the <Enter> key to be struck...
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#4
|
|||
|
|||
|
Quote:
//================================================== ========================================= Both programs run fine and didn't run into any problems. The Lost Fortune was interesting I think. The Game Designer's Network was ok, should add more to it. Maybe you're using an old compiler? //================================================== ========================================= |
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
Quote:
|
|
#7
|
|||
|
|||
|
Quote:
//============================================= not sure. I'm using microsoft visual c++ 6.0 //============================================= |
|
#8
|
|||
|
|||
|
Quote:
well then i hae mircosoft and borland cause then that means i need to spent money to get the visual 6 when i already got builder 6 damn microsoft and borland!!! ![]() |
|
#9
|
||||
|
||||
|
Quote:
|
|
#10
|
|||
|
|||
|
Quote:
thats y!!! |
|
#11
|
||||
|
||||
|
Don't worry, the problem is not that you need to buy MSVC, the problem is in the code.
The "return" statement in main will exit the program when it is reached. Where ever you have "return" in your main() function, when the program reaches that point it will automatically exit. Thus, any code behind that statement does NOT get executed, ever. Try placing the following two lines at the end of your code, BEFORE "return": Code:
fseek(stdin,0L,SEEK_END); cin.get(); This might clear up a problem with the keyboard's buffer. It works fine for me. Also, if you wish to use a different compiler than Borland, you can try Dev-Cpp -- its free and easy to use. |
|
#12
|
|||
|
|||
|
Quote:
WHERE DO YOU LEARN THESE STUFF IF ITS BOOK PLZ TELL CAUSE I WANT TO READ IF ITS FROM A SCHOOL THEN WHATEVER TOO BAD FOR ME CAUSE I AM ONLY 14 AM NOT GOIN TO ANY COLLEGE SOON SO YEAH WHERE THEY HELL U LEARNED THIS AND IF ITS A SITE PLZ BUT LINK IF ITS BOOK THEN SAY WHICH ONE SO I CAN BUY THANKS A LOT YOU HELP ME TO SAVE A LOT OF MONEY ANYWAYS WITH THAT OTHER COMPILER YEAH I HAVE THAT IN A DISC CAUSE IT CAME WITH THE BOOK I GOT THE SOURCE CODES IN WHICH IS CALLED Beginning C++ Game Programing by Micheal Dawson Yeah thanks a lot |
|
#13
|
||||
|
||||
|
Well, I don't remember where I learned that specific "trick", but in general the fun stuff I learn come from forums where I myself ask questions, or from random Internet tutorials....
|
|
#14
|
||||
|
||||
|
You could also just use
Code:
system ("PAUSE");
works for me, I use visual studio, and Dev-cpp |
|
#15
|
|||
|
|||
|
Quote:
|
|
#16
|