C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 22nd, 2005, 06:25 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
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

Reply With Quote
  #2  
Old July 22nd, 2005, 08:30 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
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

Reply With Quote
  #3  
Old July 23rd, 2005, 04:09 AM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
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.



Reply With Quote
  #4  
Old July 23rd, 2005, 12:51 PM
jayv jayv is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 4 jayv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 37 m 51 sec
Reputation Power: 0
Quote:
Originally Posted by BloodlustShaman
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

//================================================== =========================================
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?
//================================================== =========================================

Reply With Quote
  #5  
Old July 24th, 2005, 07:10 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by B-Con
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...
does it work with you cause with it didnt it still gots the problems that it closes

Reply With Quote
  #6  
Old July 24th, 2005, 07:12 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by jayv
//================================================== =========================================
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?
//================================================== =========================================
well i use borland c++ builder 6 is that old enough to be called old compiler?

Reply With Quote
  #7  
Old July 24th, 2005, 08:24 PM
jayv jayv is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 4 jayv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 37 m 51 sec
Reputation Power: 0
Quote:
Originally Posted by BloodlustShaman
well i use borland c++ builder 6 is that old enough to be called old compiler?


//=============================================

not sure. I'm using microsoft visual c++ 6.0

//=============================================

Reply With Quote
  #8  
Old July 26th, 2005, 07:03 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by jayv
//=============================================

not sure. I'm using microsoft visual c++ 6.0

//=============================================


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!!!

Reply With Quote
  #9  
Old July 26th, 2005, 07:18 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
Quote:
Originally Posted by BloodlustShaman
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!!!
why do you need to buy MSVC?

Reply With Quote
  #10  
Old July 27th, 2005, 05:05 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by B-Con
why do you need to buy MSVC?
becuase jayv says that those 2 programs that i have there works meaning that the one i got wont work with these things cause almost everytimes i use the reurn 0 it will close as soon i open it and i see that MSVC works on those programs and i am mad cause my cousin bought me this saying that it will do everything i do in programing and i want to try these 2 simple programs and it wont work right when he says that in MSVC it works with same source code!

thats y!!!

Reply With Quote
  #11  
Old July 27th, 2005, 07:30 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
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.

Reply With Quote
  #12  
Old July 27th, 2005, 10:37 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by B-Con
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.
YES FINALLY IT WORKS THANKS A LOT!!!!!
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

Reply With Quote
  #13  
Old July 28th, 2005, 02:40 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
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....

Reply With Quote
  #14  
Old July 31st, 2005, 09:35 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
You could also just use
Code:
system ("PAUSE");

works for me, I use visual studio, and Dev-cpp

Reply With Quote
  #15  
Old July 31st, 2005, 10:41 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by Geo.Garnett
You could also just use
Code:
system ("PAUSE");

works for me, I use visual studio, and Dev-cpp
nope that doesnt work for me but thanks anyways i use borland C++ builder 6 and i do not recommend it for anybody but thanks for that message

Reply With Quote
  #16  
Old August 1st, 2005, 05:10 AM