If Statement not running

I've got my final due tomorrow at 7pm and I'm having a lot of trouble with some random stuff. If statements just not running mostly. It's not done yet obviously. Also, feel free to email me. I'd like to make some friends that can help me and have cool conversations with. misspinkiepool@gmail.com

Thanks :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  #include <iostream>
#include <string>

using namespace std;

void Battle();
void Shop();

int main(void)
{
	string Name = "";
	string Class = "";
	
	int Health = 0;
	int Damage = 0;
	int DHealth = 500;


	cout << "Choose a name:" << endl;
	cin >> Name;
	cout << "Welcome " << Name << endl;
	cout << "Please pick a class." << endl;
	cout << "Crusader\t 200 Health\t50 Damage" << endl;
	cout << "Assassin\t 100 Health\t150 Damage" << endl;
	cout << "Fighter\t\t 125 Health\t100 Damage" << endl;
	cin >> Class;
	cout << "Welcome to the world of Orin, " << Name << " the " << Class << endl;
	cout << "Youre goal is to defend the king and queen from the Dark One." << endl;
	cout << endl << "What would you like to do first?" << endl;

	while(true == true)
	{
		string MainPick = "";
		cout << "Battle" << endl;
		cout << "Shop" << endl;
		cout << "Socialize" << endl;
		cin >> MainPick;
		
		if (MainPick == "Shop")
		{
			Shop();
		}


	}
	system("pause");
	return 0;
}



void Shop()
{
	string ShopChoice = "";
	string ConsumChoice = "";
	float Money = 500.00f;

	cout << "Welcome to the shop!" << endl;
	cout << "You have $ " << Money << endl;
	cout << "Would you like to buy consumables or weapons?" << endl;
	cin >> ShopChoice;

	if (ShopChoice == "consumables" || "Consumables")
	{
		float Apple = 2.0f;
		float Orange = 5.0f;
		float HealthPotion = 10.0f;
		float DamagePotion = 50.0f;

		cout << "Apple\t\t$2\t+5 Health" << endl;
		cout << "Orange\t\t$5\t+10 Health" << endl;
		cout << "Health Potion\t\t$10\t+20 Health" << endl;
		cout << "Damage Potion\t\t$50\t+50 Damage" << endl;
		cin >> ConsumChoice;

		if (ConsumChoice == "Apple" || "apple")
		{
			Money -= Apple;
			cout << "Thank you for your purchase! You now have $" << Money << "left." << endl;
		}

		if (ConsumChoice == "Orange" || "orange")
		{
			Money -= Orange;
		}
		
	}
}
Last edited on
add this at the top #include <cstdlib> , the system function needs this included.
Note: you really dont need to use system(pause);

change line 19: cout << "Choose a name: ";


place the MainPick variable before the while loop and
change while(true == true) to while(MainPick == "quit") to allow you to exit out while loop if needed.

Last edited on
My if statements still aren't running though.
This is wrong
if (ConsumChoice == "Orange" || "orange")

It should look more like this
if (ConsumChoice == "Orange" || ConsumChoice == "orange")
I can't even get to the shop menu...
Try this
1
2
3
4
	if (MainPick == "Shop" || MainPick == "shop")
		           {
			   Shop();
		           }


remember everything in c++ is case sensitive
Last edited on
I had it like that about two hours ago, it didn't work then. You sir are a wizard.
if I am U i will do like this,

1
2
MainPick = toupper(MainPick);
if(MainPick == "SHOP") { Shop(); }


toupper() will make ur whole input into capital letter to allow an easier way for your project organization.
Last edited on
Topic archived. No new replies allowed.