HelpStrength Game

Posts 1–2 of 2 · Page 1 of 1
Strength Game
Hello, I am trying to create an easy game with if and else statements. I need help figuiring out if the "if and "else" statements work together because I get error when i run the program.
Code:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

int main()
{
	bool test1, test2, test3;
	int ourStrength = 10, goblinStrength = 5, trollStrength = 10, cyclopsStrength = 15;

	cout << "Welcome to the strength game\nYou walk into a cave and spots a goblin\n";

	cout << "do you engage? (1 for yes, 0 for no)\n";
	cin >> test1;

	if (test1)
	{
		cout << "you engage the goblin in combat\n";

		if (ourStrength > goblinStrength)
		{
			cout << "You easily beat the goblin\n";
		}
		else
		{
			cout << "You are not as strong as the goblin!\nGAME OVER";
			system("PAUSE");
		}
	}
	else
	{
		cout << "As you walk away the goblin throws a rock at the back of your head and you die\nGAME OVER";
		system("PAUSE");
	}

	cout << "You walk into a deep forest and spots a troll\n";

	cout << "Do you engage in combat? (1 for yes, 0 for no)\n";
	cin >> test2;

	if (test2)
	{
		if (ourStrength == trollStrength)
		{
			cout << "You and the troll walks each ways because no one can win\n GZ YOU WIN THE GAME!";
			system("PAUSE");
		}
		else (ourStrength < trollStrength)
		{
			cout << "The troll easily beats you\";
				system("PAUSE");
		}

	}

	else
	{
		cout << "troll kills you as you walk away"
			system("PAUSE");
	}






}
Solution:

Code:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

int main()
{
	bool test1, test2, test3;
	int ourStrength = 10, goblinStrength = 5, trollStrength = 10, cyclopsStrength = 15;

	cout << "Welcome to the strength game\nYou walk into a cave and spots a goblin\n";

	cout << "do you engage? (1 for yes, 0 for no)\n";
	cin >> test1;

	if (test1)
	{
		cout << "you engage the goblin in combat\n";

		if (ourStrength > goblinStrength)
		{
			cout << "You easily beat the goblin\n";
		}
		else
		{
			cout << "You are not as strong as the goblin!\nGAME OVER";
			system("PAUSE");
		}
	}
	else
	{
		cout << "As you walk away the goblin throws a rock at the back of your head and you die\nGAME OVER";
		system("PAUSE");
	}

	cout << "You walk into a deep forest and spots a troll\n";

	cout << "Do you engage in combat? (1 for yes, 0 for no)\n";
	cin >> test2;

	if (test2)
	{
		if (ourStrength == trollStrength)
		{
			cout << "You and the troll walks each ways because no one can win\n GZ YOU WIN THE GAME!";
			system("PAUSE");
		}
		else if (ourStrength < trollStrength) // You need to use the "else if" statement here
		{
			cout << "The troll easily beats you\n"; //You forgot the "n"                 
            system("PAUSE");
		}

	}

	else
	{
		cout << "troll kills you as you walk away"; //You forgot the semicolon
			system("PAUSE");
	}
Try to avoid "System" there are several explanations why, in this case you could use for example "return 0" to exit the program
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us