What's wrong with this code?

Started by
2 comments, last by AeroBLASTER 21 years, 8 months ago

    
	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]
---DirectX gives me a headache.
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.
The bracket is in the incorrect place.

check the brakets before and after the section


   <--------------------------else if (weppurchase == 2)  |{                           |}                           |} >------------->-----------/  
Ah. I see now Now I feel stupid - oh well - thanks guys!
---DirectX gives me a headache.

This topic is closed to new replies.

Advertisement