Question:

Can anyone help me fix this program? C++ parse error...?

by  |  earlier

0 LIKES UnLike

Everytime I try to compile this it says "parse error at end of input". Can anyone help me figure out how to fix this to get it to run?

//

// Create a window asking the operator for input regarding their base damage value

// and then require the computer to calculate the resulting damage that does

// to a leveled monster, using that monster's health value

//

#include <cstdio>

#include <cstdlib>

#include <iostream>

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])

{

// enter the attack value of your character

int attack;

cout << "Enter the base Attack Value of your character:";

cin >> attack;

// define the possible integer values for the different

// creature name types entered

int nRobot;

nRobot = 50;

int nAnimal;

nAnimal = 40;

int nHumanoid;

nHumanoid = 40;

int nMonster;

nMonster = 70;

// enter the base health of the enemy creature

int kind;

cout << "Enter the number corresponding to the enemy creature type:";

cin >> kind;

// define the type value depending on the creature type

switch(kind)

{

case 1:

int health;

health = nMonster;

break;

case 2:

health = nAnimal;

break;

case 3:

health = nHumanoid;

break;

case 4:

health = nRobot;

break;

default:

cout << "You didn't enter a valid creature type\n";

// spawn random number for later use

int randomNumber;

randomNumber = rand()%11;

// calculate equation for damage done to health depending on

// attack value

int nBonus;

nBonus = 10 + randomNumber;

// use equation number to determine final enemy health depending

// on relative damage done

int enemyHealth;

enemyHealth = health - (attack+nBonus);

// output the results (followed by a NewLine)

cout << "Enemy Health is:";

cout << enemyHealth << endl;

// wait until user is ready to close the window

system("PAUSE");

return 0;

}

 Tags:

   Report

2 ANSWERS


  1. Issue 1: Martin is correct.  You need to end your switch statement with a closing brace after the default statement.

    Issue 2: In your switch statement, the variable &quot;kind&quot; must have a value of 1 in order for there to be memory allocated for the variable &quot;health&quot;.  For memory to be allocated for the variable &quot;health&quot; regardless of the value of &quot;kind&quot;, move the statement &quot;int health;&quot; to a location prior to your switch statement.


  2. Oh man. Your problems are so big.

    Parse errors occur often when there are syntax errors. Your switch statement&#039;s open curly bracket lacks a close curly bracket.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.