Need help with my attack sequnce

So i’m coding an attack sequence for a text based game but i can’t get it to compile.

Its basically just a while loop with a bunch of nested ifs.

Maybe i just need more review, bare in mind I’m only “attacking” the enemy, I don’t have any enemy attacks.

Thank you for any advice.

code is below(In C++):

#include <iostream>
#include <string>
#include <vector>


//attack sequence


//variables
char choice;

int enemyHealth;
int playerHealth;
char combat;
char attackAgain;
char flee;



int attackSeq()
{
	while (enemyHealth && playerHealth > 100)
	{
		std::cout << "Would you like to attack?/n enter y for yes or n for no";
		
		int combatSequence();
		{
			
			if (combat == 'y')
			{
				
				return enemyHealth = (enemyHealth - 40);
				
				
				if (enemyHealth > 0)
				{
					std::cout << "Would you like to attack again?/n enter y for yes or n for no";
					
					
					if (attackAgain == 'y')
					{
						return enemyHealth = (enemyHealth - 40);

					}

					else if (attackAgain == 'n')
					{
						std::cout << "Would you like to run away?/n enter y for yes or n for no";
						
						if (flee == 'y')
						{
							std::cout << "You ran away!";
							return 0; //exit loop
						}
						else if (flee == 'n')
						{
							return 0;
						}

					}
					else
					{
						std::cout << "Sorry i didnt get that. ";
					}


				}

			}
			else if (combat == 'n')
			{
				std::cout << "Would you like to run away?/n enter y for yes or n for no";
				char flee;
				if (flee == 'y')
				{
					std::cout << "You ran away!";
					return 0; //exit loop
				}
				else if (flee == 'n')
				{
					return 0;
				}




			}

		}

	}

}


int main()
{
	std::cout << "You are being attacked! What would you like to do? /n f = fight, e = escape";
	std::cin >> choice;
	{
		if (choice == 'f')
		{
			attackSeq();
		}

		else if (choice == 'e')
		{
			std::cout << "You ran away!";

		}

		else
		{
			std::cout << "Sorry, I didnt get that.";
		}
	}

	return 0;

}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

There are some compile warnings, but no errors on repl:

 clang++-7 -pthread -std=c++17 -o main main.cp
main.cpp:26:21: warning: empty parentheses
      interpreted as a function declaration
      [-Wvexing-parse]
                int combatSequence();
                                  ^~
main.cpp:26:21: note: replace parentheses with
      an initializer to declare a variable
                int combatSequence();
                                  ^~
                                   = 0
main.cpp:93:1: warning: control may reach end of
      non-void function [-Wreturn-type]
}
^

I realize this.

Its just, I’m a novice and so i can’t figure out how to fix these compile errors.

My compiler also lists different errors.

C4552 ‘-’ result of expression not used
C4715 ‘attackSeq’: not all control paths return a value
C4700 uninitialized local variable ‘flee’ used

We are using these words differently it seems:

Your code did compile for me. It’s running at that repl link.

Warnings and errors are different things:

Warning - The compiler warning you that you may have a problem (you probably do when you get a warning)
The code does compile.

Error - The compiler telling you that it could not finish compiling your code because it is malformed in some fashion.
The code does not compile.

That fact that you have defined the function combatSequence() inside of the function attackSeq() is bizarre and confusing the compiler.

Ok, i’ll just try and rewrite the function.

thanks for your help.

So I guess what I want is for the program to run?

I removed the attackSeq() function from with the while loop and it still doesn’t.

In addition i defined ‘flee’ as a variable along with the other variables and its still being flagged as ‘uninitialized’.

I guess maybe I’ll just wait for class, thought it would be a quick fix.

Yeah, I don’t think that this is a quick fix. The problem is that you have defined functions inside of functions, which is a) a bad idea and b) not needed in this case

I think you leapt into writing code too quickly before diagramming your logic and what you want to do. If you were to make a flow chart or bulleted list of your logic, what would it look like?