Math Error

Hello, I'm in the middle of programming my first text - based game right now. I am having a mathematical error...At the end of my code, for some reason, it keeps saying I have 55 health points and 70 mana points...I don't know why this is..here is my code , please help. ( By the way, it may seem a bit unorganized by the way the output is displayed, but I'm going to clean it up after )


// First Complex Game

#include <iostream>
#include <string>
using namespace std;
using namespace std;

int main()
{
const int SMALLMOB_LOOT = 10;
const int LARGEMOB_LOOT = 15;
const int BOSS_LOOT = 30;
int HEALTH_POINTS = 50;
int MANA_POINTS = 50;
int SMALL_MOBHP = 15;
int LARGE_MOBHP = 30;
int BOSS_HP = 50;
int COMBAT_CLASSES;
int INTELLECT_CLASSES;
string character;
string CLASS_CHOICE;

// Personalizing the character

cout << "\tWelcome To Huntswin! The Medieval School!\n";

cout << "\nWhat is your name young one?: ";
cin >> character;

cout << "\nWelcome " << character << " to Huntswin Medieval school!\n";

cout << "\nHuntswin offers three different courses here,here are you options: \n";
cout << "Soldier , Archer, or Sorcerer! Soldiers have the most health, as the Archer doesthe most damage as the socerer has the most mana!\n";
cout << "Type the class you would want to be!(Case sensitive) : ";
cin >> CLASS_CHOICE;

cout << "\nAh you wish to be a " << CLASS_CHOICE << " , nice decision. I feel like you will succeed in yourrole.\n";
cout << "Well you should report to your classes! You will be taking a total of 5 classes to graduate!";
cout << "The two classes we will offer are Combat Training and Intellect Challenge!\n";
cout << "Combat training will help increase your stamina, making you survive longer.";
cout << " Intellect Challenge will help increase your knowledge, giving you energy to perform more attacks.\n";
cout << "How many Combat Training classes will you like to attend? ( pick a number 0-5 ):";
cin >> COMBAT_CLASSES;
cout << "Ah so you will then be attending " << 5 - COMBAT_CLASSES << " Intellect Challenge classes due to the number of combat classes you will be attending.\n\n";

if ( COMBAT_CLASSES = 0)
{
MANA_POINTS += 25;
}

else if ( COMBAT_CLASSES = 1)
{
HEALTH_POINTS += 5;
MANA_POINTS += 20;
}

else if ( COMBAT_CLASSES = 2)
{
HEALTH_POINTS += 10;
MANA_POINTS += 15;
}

else if ( COMBAT_CLASSES = 3)
{
HEALTH_POINTS += 15;
MANA_POINTS += 10;
}

else if ( COMBAT_CLASSES = 4)
{
HEALTH_POINTS += 20;
MANA_POINTS += 5;
}

else if ( COMBAT_CLASSES = 5)
{
HEALTH_POINTS += 25;
MANA_POINTS += 0;
}

cout << "Time passes as " << character << " goes through his classes.\n";
cout << character << " now has " << HEALTH_POINTS << " health points and " << MANA_POINTS << " mana points due to your selection of classes.";


return 0;



}
cin returns strings and you're comparing that to numbers...
So how would i fix it? ( Sorry i've been using c++ for just a week now)
I don't agree with cnoeval's assessment.

It looks like your problem is due to confusing assignment (=) with comparison (==).

Here is one example:

if ( COMBAT_CLASSES = 0)

You meant to do this:

if ( COMBAT_CLASSES == 0)

Note the use of == instead of =.

= 0 will actually assign the value of zero to COMBAT_CLASSES.
== 0 will compare zero with the value currently in COMBAT_CLASSES


You do this in numerous places in your code.


Also... please put your code in [code]code tags[/code]
Oh Thank you so much!
Now is there anyway I can add words/strings to integers? like this


1
2
3
4
5
6
7
8
9
int CLASS_CHOICE;

cout << "What class would you like to be? : ";
cin >> CLASS_CHOICE;

[if (CLASS_CHOICE == 'Archer')
{
SPELL_ONE += 'Flame Arrow' ;
}
Last edited on
I believe you just declare the variable as a "string" variable, like this:

1
2
3
4
5
6
7
8
9
string CLASS_CHOICE;

cout << "What class would you like to be? : ";
cin >> CLASS_CHOICE;

[if (CLASS_CHOICE == 'Archer')
{
SPELL_ONE += 'Flame Arrow' ;
}
You'll need to use double quotes around your string literals, as single quotes are for individual character literals only.
Now is there anyway I can add words/strings to integers?

No. If you want to store a string, then use a string. Why would you use an integer variable when you want to store a string?
Topic archived. No new replies allowed.