Insert BS here A place to discuss anything you want

I need help with C++

Thread Tools
 
Search this Thread
 
Old 08-11-2007, 09:19 PM
  #21  
Elite Member
iTrader: (12)
 
neogenesis2004's Avatar
 
Join Date: Aug 2006
Posts: 4,413
Total Cats: 20
Default

also, at the end of your program you have the selection as y or n, not 1 or 2.
neogenesis2004 is offline  
Old 08-11-2007, 09:29 PM
  #22  
Elite Member
iTrader: (12)
 
neogenesis2004's Avatar
 
Join Date: Aug 2006
Posts: 4,413
Total Cats: 20
Default

also, im not sure if the copy paste did it, but if not you need to work on your indenting
neogenesis2004 is offline  
Old 08-11-2007, 09:34 PM
  #23  
y8s
2 Props,3 Dildos,& 1 Cat
iTrader: (8)
 
y8s's Avatar
 
Join Date: Jun 2005
Location: Fake Virginia
Posts: 19,338
Total Cats: 573
Default

Chicks dig computers.

y8s is offline  
Old 08-11-2007, 09:35 PM
  #24  
Elite Member
iTrader: (12)
 
neogenesis2004's Avatar
 
Join Date: Aug 2006
Posts: 4,413
Total Cats: 20
Default

that chick looks like shes in to giving blumpkins
neogenesis2004 is offline  
Old 08-11-2007, 10:11 PM
  #25  
Elite Member
iTrader: (12)
 
neogenesis2004's Avatar
 
Join Date: Aug 2006
Posts: 4,413
Total Cats: 20
Default

after looking at it forever (again, i hate debugging) I remembered that when trying to show equalities you must use == instead of =. I haven't had to program anything other than assembly for the last 2 semesters.

For example:

while(blah = 1) actually passes the value of 1 to blah by reference
while(blah == 1) only compares to see if the value in blah is 1

That is the fundamental reason why your main loop was not functioning. There are some other errors in there too. Here is the working code with some of my minor corrections.

#include<iostream>
#include<string>
using namespace std;

int main (){
int choice = 1, choice2 = 0, choice3 = 0, choice4 = 0, choice5 = 0;
bool quit = false;
int soldiers = 0, killed = 0, survivors = 0;
string leader;

while(choice == 1) {
//This is the introduction screen and asks the player to input important
//information.
cout<<"******************************************* *************"<<endl;
cout<<"** Welcome to the game **"<<endl;
cout<<"******************************************* *************"<<endl;
cout<<"\t\nPlease enter the following information"<<endl;
//Here the player will input the number of adventurers, survivors as well as the
//players name. These will all be used further along in the story.

cout<<"\nEnter a number: ";
cin>>soldiers;
do{
cout<<"\nEnter a number smaller than the first: ";
cin>>killed;
if (killed>soldiers)
cout<<"Invalid number.";
}while (killed>soldiers);

survivors=soldiers-killed;

cout<<"\nEnter your name: ";
cin>>leader;
//This is the story segment. The above numbers that the player put in are
//put into context down below.
cout<<"******************************************* ******************************"<<endl;
cout<<"******************************************* ******************************"<<endl;
cout<<"\nA group of explorers set out to map their land. Along the way they were"<<endl;
cout<<"attacked by a rouge group from another village. In retaliation the"<<endl;
cout<<"King sent the foolish General Tivian to avenge the murdered explorers."<<endl;
cout<<"The General and all soldiers were lost. The King was outraged."<<endl;
cout<<"\nA brave group of "<<soldiers<<" soldiers were sent out to march across"<<endl;
cout<<"the land. This group was led by the legendary General, "<<leader<<".\n"<<endl;
cout<<"This group was also attacked, and "<< killed <<" of the men were killed."<<endl;
cout<<"The soldiers had fought hard, and most of their weapons and armor had"<<endl;
cout<<"been heavily damaged."<<endl;
cout<<"\nThe surviving members all want to move on, but they have no equipment."<<endl;
cout<<"\nWhat should the group do?"<<endl;
cout<<"******************************************* *****************************"<<endl;
cout<<"* Your choices are: *"<<endl;
cout<<"* 1-Press on *"<<endl;
cout<<"* 2-Run home *"<<endl;
cout<<"* Enter your selection: *"<<endl;
cout<<"******************************************* *****************************"<<endl;
cin>>choice;

switch(choice)
{
case 1:
cout<<"\nYou rally the troops and press on!"<<endl;
break;
case 2:
cout<<"\nThe troops laugh at you and force you to keep going!"<<endl;
break;
default:
cout<<"\nYou must make a valid choice!"<<endl;
}
cout<<"The soldiers and their leader "<<leader<<" continued on through the night."<<endl;
cout<<"The next morning they started their long journey to the offending village."<<endl;
cout<<"Just before settling down for lunch the group came across a massive"<<endl;
cout<<"cave."<<endl;
cout<<endl;
cout<<"******************************************* *****************************"<<endl;
cout<<"* Will you explore the cave?: *"<<endl;
cout<<"* 1-Lets check it out! *"<<endl;
cout<<"* 2-We have no equipment, we are in no shape to explore. *"<<endl;
cout<<"* Enter your selection *"<<endl;
cout<<"******************************************* *****************************"<<endl;
cin>>choice2;

switch(choice2)
{
case 1:
cout<<"\nThe cave has a hidden army surplus, you have";
cout<<"plenty of new equipment"<<endl;
cout<<"for everyone!"<<endl;
cout<<"Newly fitted with equipment the soldiers spirits are"<<endl;
cout<<"high. They proudly march on and come across the "<<endl;
cout<<"village they had been looking for."<<endl;
cout<<endl;
break;
case 2:
cout<<"\nThe group sits down for lunch. This uses up the"<<endl;
cout<<"last of the food they have. Tired, they all march on."<<endl;
cout<<"Over the next hill, they can see the village."<<endl;
break;
default:
cout<<"\nYou must make a valid choice!"<<endl;
}

cout<<"The troops want to fight right away, but being the brilliant general "<<endl;
cout<<leader<<" is,the group is brought together to decide what to do next."<<endl;
cout<<endl;
cout<<"******************************************* *****************************"<<endl;
cout<<"* What will you and your troops do?: *"<<endl;
cout<<"* 1-Charge in! *"<<endl;
cout<<"* 2-Wait for reinforcements *"<<endl;
cout<<"* Enter your selection *"<<endl;
cout<<"******************************************* *****************************"<<endl;
cin>>choice3;

switch(choice3)
{
case 1:
cout<<"\nYou rush in and kill most of the offenders,"<<endl;
cout<<"but they end up killing all but 2 of the men. "<<endl;
cout<<"You return home and the family members of the "<<endl;
cout<<"dead men are furious. You are cast out of your "<<endl;
cout<<"village and become a beggar."<<endl;
cout<<endl;



break;
case 2:
cout<<"You wait for reinforcements and you take the base"<<endl;
cout<<"with little trouble. You return home a hero, and given"<<endl;
cout<<" a large palace."<<endl;
break;
default:
cout<<"You must make a valid choice!";
}

cout<<"******************************************* *****************************"<<endl;
cout<<"* *"<<endl;
cout<<"* Do you want to play again (1 = Yes/ 2 = No)? *"<<endl;
cout<<"* 1-Yes *"<<endl;
cout<<"* 2-No *"<<endl;
cout<<"* *"<<endl;
cout<<"******************************************* *****************************"<<endl;
cin>>choice5;
}
cout<<"THE END!"<<endl;
}
neogenesis2004 is offline  
Old 08-11-2007, 10:13 PM
  #26  
Elite Member
iTrader: (12)
 
neogenesis2004's Avatar
 
Join Date: Aug 2006
Posts: 4,413
Total Cats: 20
Default

Another HUGE problem with your program is that any value input in other than a number causes an infinite loop. I'm not sure if you've been taught how to stop that or if your teacher even cares at your current level.
neogenesis2004 is offline  
Old 08-11-2007, 10:40 PM
  #27  
:(
iTrader: (7)
 
magnamx-5's Avatar
 
Join Date: Jul 2006
Location: nowhere
Posts: 8,255
Total Cats: 4
Default

Originally Posted by y8s
Chicks dig computers.

Is that your girl Apple huh
magnamx-5 is offline  
Old 08-11-2007, 11:48 PM
  #28  
Senior Member
Thread Starter
iTrader: (1)
 
miataspeed1point6's Avatar
 
Join Date: Feb 2006
Location: Detroit
Posts: 1,234
Total Cats: 0
Default

Thanks ALOT for all the help. The copy and paste messed up the indents, and it looks like I forgot to comment the rest of the code.

I knew when you put in another number besides 1 and 2 it would screw up, but I wasn't sure how to fix it. I'm going to look over everything you changed and figure out what you did to make all the bugs work.

This is only my 4th class. I'm trying to read through the book but it gets really confusing really fast.

Again thanks alot, I really appreciate it.
miataspeed1point6 is offline  
Old 08-11-2007, 11:52 PM
  #29  
Elite Member
iTrader: (12)
 
neogenesis2004's Avatar
 
Join Date: Aug 2006
Posts: 4,413
Total Cats: 20
Default

ya, I know what you mean about the books. Luckily the way they teach programming here at VT is without books. All the classes are very interactive and we have to work on examples in class along with the professor so that we can learn by doing. All our programming classes require laptops in class (at least the ones i've taken).
neogenesis2004 is offline  
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
z31maniac
Insert BS here
13
09-22-2015 02:59 PM
JasonC SBB
ECUs and Tuning
2
09-21-2010 11:39 AM
noth1ngmuch
Meet and Greet
8
10-27-2009 02:22 PM
UrbanSoot
MEGAsquirt
9
01-14-2008 05:06 PM
arga
Insert BS here
27
05-08-2007 12:44 PM



Quick Reply: I need help with C++



All times are GMT -4. The time now is 02:15 PM.