Trying to make a console game.Help.

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
#include "stdafx.h"
#include <iostream>
int main()
{
	int SerildaHP;
	int LunaHP;
	SerildaHP = 1000;
	LunaHP = 1000;
	std::cout << "Welcome Back, Serilda!";
	std::cout << "To start game, click 1 , to exit, click 2!";   //only works till here
	int startOrEnd;
	std::cin >> startOrEnd;
	if (startOrEnd = 1)
	{
		while (LunaHP != 1000)
		{
			std::cout << "THE BATTLE HAS BEGUN!Click 1 or 2 to switch skills!";
			int Skill;
			std::cin >> Skill;


			if (Skill = 1)
			{
				int a = rand() % 4;
				std::cout << "You dealt" << a << "% of Luna's HP.";
				LunaHP = LunaHP - a;
			}
			else if (Skill = 2)
			{
				int b = rand() % 6;
				std::cout << "You dealt" << b << "% of Luna's HP.";
				LunaHP = LunaHP - b;
			}
		}




		if (LunaHP = 0){
			std::cout << "You've won!";
		}
	}

	else if (startOrEnd = 2)
	{
		std::cout << "We're sorry to see you go:(";
	}
}
Last edited on
All of the equals for your if statements need to be double equals for an equality test: == The single equal sign assigns a value to the variable. Also, your while condition will always be false the way you have it. LunaHP will always be 1000 when you first hit the loop.

Edit... You should also seed rand() so the results are not the same every time. And, I changed LunaHP to 10 so it wouldn't take forever to win.

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

#include <iostream>
int main()
{
	int SerildaHP;
	int LunaHP;
	SerildaHP = 1000;
	LunaHP = 10;
	std::cout << "Welcome Back, Serilda!";
	std::cout << "To start game, click 1 , to exit, click 2!";   //only works till here
	int startOrEnd;
	std::cin >> startOrEnd;
	if (startOrEnd == 1)
	{
		while (LunaHP > 10)
		{
			std::cout << "THE BATTLE HAS BEGUN!Click 1 or 2 to switch skills!";
			int Skill;
			std::cin >> Skill;


			if (Skill == 1)
			{
				int a = rand() % 4;
				std::cout << "You dealt" << a << "% of Luna's HP.";
				LunaHP = LunaHP - a;
			}
			else if (Skill == 2)
			{
				int b = rand() % 6;
				std::cout << "You dealt" << b << "% of Luna's HP.";
				LunaHP = LunaHP - b;
			}
		}




		if (LunaHP == 0){
			std::cout << "You've won!";
		}
	}

	else if (startOrEnd == 2)
	{
		std::cout << "We're sorry to see you go:(";
	}
}
Last edited on
Thanks so much :)
Topic archived. No new replies allowed.