• Advertisement

Archived

This topic is now archived and is closed to further replies.

What's wrong with this code?

This topic is 5672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


    
	if (wORa == 1)
	{
		cout << "\n\nLooking for some high-quality weaponry, eh?  Well, here's what I've got!\n\n";
		cout << "1) " << blade << "\nDamage: " << bladestat << "\nPrice: " << bladeprice << "\n\n";	
		cout << "2) " << broadsword << "\nDamage: " << broadswordstat << "\nPrice: " << broadswordprice << "\n\n";
		cout << "3) " << longsword << "\nDamage: " << longswordstat << "\nPrice: " << longswordprice << "\n\n";
		cout << "4) " << enchantedclaymore << "\nDamage: " << enchantedclaymorestat << "\nPrice: " << enchantedclaymoreprice << "\n\n";
		cout << "You have " << playergp << " gold.\n\n";
		cout << "Either type the number of your desired purchase, or type 5 to go back to the\n";
		cout << "Game menu.  ";
		cin >> weppurchase;
			if (weppurchase == 1)
			{
				if (playergp >= bladeprice)
				{
					cout << "\n\nYou have purchased a Blade.  Thanks, and have a nice day!";
					playergp = playergp - bladeprice;
					playerwep = bladestat;
					strcpy (playerwepname, blade);
				}
				else if (playergp < bladeprice)
				{
					cout << "\n\nYou do not have enough gold to purchase that weapon.";
				}
			else if (weppurchase == 2)
			{
				if (playergp >= broadswordprice)
				{
					cout << "\n\nYou have purchased a Broadsword.  Thanks, and have a nice day!";
					playergp = playergp - broadswordprice;
					playerwep = broadswordstat;
					strcpy (playerwepname, broadsword);
				}
				else if (playergp < broadswordprice)
				{
					cout << "\n\nYou do not have enough gold to purchase that weapon.";
				}
			}
			}
			else if (weppurchase == 1337)
			{
				cout << "In a magestic sparkling of light, 500 gold mysteriously appears in your wallet!";
				playergp = playergp + 500;
			}
	}  
Okay, so basically what this is is a weapon purchasing system. The "weppurchase == 1337" portion is just a 'cheat code' for testing. The problem is, while the first selection works fine (the blade part), the second (the broadsword part) doesn't work at all - it doesn't do anything. What am I missing? [edited by - AeroBLASTER on August 14, 2002 4:08:45 PM]

Share this post


Link to post
Share on other sites
Advertisement
You have put a closing brace in the wrong place, so that your else if becomes part of

if (playergp >= bladeprice)

Look closely at your code, match up the braces with their counterparts.

Share this post


Link to post
Share on other sites
The bracket is in the incorrect place.

check the brakets before and after the section


  
<--------------------------
else if (weppurchase == 2) |
{ |
} |
} >------------->-----------/

Share this post


Link to post
Share on other sites

  • Advertisement