I'm new to c++, I'm trying to read values from a text file and push only the integers to a stack. The issue I'm having is that when I do a pop() the value that comes out of the stack is different.
For example if I push a 4, when I do a pop it comes out as 52.
What am I doing wrong and how can I fix it?
IntegerStack.cpp
#include "IntegerStack.h"
#include <cstdlib>
using namespace std;
IntegerStack::IntegerStack()
{
used = 0;
}
void IntegerStack::push(int entry)
{
data[used] = entry;
++used;
}
int IntegerStack::pop()
{
--used;
return data[used];
}
int IntegerStack::peek() const
{
return data[used-1];
}
IntegerStack.h
#ifndef INTEGERSTACK_H
#define INTEGERSTACK_H
#include <cstdlib> // Provides the type size_t.
using namespace std;
class IntegerStack
{
public:
// MEMBER CONSTANT
static const std::size_t CAPACITY = 100;
// DEFAULT CONSTRUCTOR
IntegerStack( ); // Inline
// MODIFICATION MEMBER FUNCTIONS
void push ( int entry );
int pop ( );
// CONSTANT MEMBER FUNCTIONS
std::size_t size ( ) const { return used; } // Inline
bool is_empty ( ) const { return used == 0; } // Inline
int peek ( ) const;
private:
// DATA MEMBERS
int data[CAPACITY];
std::size_t used;
};
#endif // INTEGERSTACK_H
main.cpp
#include <fstream>
#include <iostream>
#include "IntegerStack.h"
using namespace std;
int main()
{
string content;
ifstream inputFile;
cout << "Enter input file name: ";
cin >> content;
IntegerStack operandStack;
// Open file
inputFile.open(content.c_str());
if(inputFile)
{
// Place values in the stack
while(getline(inputFile,content))
{
cout << "Expression: " << content << endl;
for (int i = 0; i < content.size(); i++)
{
if(isdigit(content[i]))
{
cout << "Adding " << content[i] << " to operandStack" << endl;
operandStack.push(content[i]);
int number = operandStack.pop();
cout << "The integer we just pushed: " << number << endl;
}
else
{
// add it to operatorStack
}
}
}
}
// Close file
inputFile.close();
return 0;
}
inix.dat
8 + 4 / 2
( 7 * 4 ) - 2
OUTPUT
Enter input file name: infix.dat
Expression: 8 + 4 / 2
Adding 8 to operandStack
The integer we just pushed: 56
Adding 4 to operandStack
The integer we just pushed: 52
Adding 2 to operandStack
The integer we just pushed: 50
Expression: ( 7 * 4 ) - 2
Adding 7 to operandStack
The integer we just pushed: 55
Adding 4 to operandStack
The integer we just pushed: 52
Adding 2 to operandStack
The integer we just pushed: 50
Process returned 0 (0x0) execution time : 4.762 s
Press any key to continue.
I was able to solve this by changing operandStack.push(content[i]); to operandStack.push(content[i]- '0');
Related
In C++, how to use a two-dimensional dynamic vector to sum up each column for the matrix in the txt file, and print out the content of the txt file and the result of summing up each column?
After searching through the Internet, I got the following code, but it only sums up a single column. The result I want to get is that no matter how many columns there are in the txt file, I can do the sum of each column.
data.txt figure
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
int main() {
ifstream myfile("data.txt");
if (!myfile.is_open()) {
cout << "Unable to open myfile";
system("pause");
exit(0);
}
vector<string> vec;
string temp;
while (getline(myfile, temp))
{
vec.push_back(temp);
}
vector <float> radius;
cout << "Processing time: " << endl;
for (auto it = vec.begin(); it != vec.end(); it++)
{
cout << *it << endl;
istringstream is(*it);
string s;
int pam = 0;
while (is >> s)
{
if (pam == 0)
{
float r = atof(s.c_str());
radius.push_back(r);
}
pam++;
}
}
cout << "matrix: " << endl;
double sum;
sum = 0;
for (auto it = radius.begin(); it != radius.end(); it++)
{
sum += *it;
}
cout << sum << endl;
system("pause");
return 0;
}
I want to sum each column in the txt file, as shown in the image below:
result
The first thing you should do is not concern yourself with where the data is coming from. Instead, you should write a function that takes the data, regardless of where it comes from, and outputs the totals.
The simplest way to represent the input data is to use a std::vector<std::vector<float>>. Thus a function to create the totals would return a std::vector<float> that represents the totals.
Here is an example of such a function:
#include <vector>
#include <numeric>
// Pass in the data
std::vector<float> getTotals(const std::vector<std::vector<float>>& myData)
{
std::vector<float> totals(myData[0].size());
for (size_t i = 0; i < totals.size(); ++i)
{
// call std::accumulate for each column i
totals[i] = std::accumulate(myData.begin(), myData.end(), 0,
[&](int total, auto& v)
{ return total + v[i]; });
}
// return the totals
return totals;
}
The above function uses std::accumulate to total the values in column i, and store the total for that column in totals[i].
Once this function is written, it can then be tested. Here is a full example:
#include <vector>
#include <numeric>
#include <iostream>
std::vector<float> getTotals(const std::vector<std::vector<float>>& myData)
{
std::vector<float> totals(myData[0].size());
for (size_t i = 0; i < totals.size(); ++i)
{
totals[i] = std::accumulate(myData.begin(), myData.end(), 0,
[&](int total, auto& v)
{ return total + v[i]; });
}
return totals;
}
void printTotals(const std::vector<std::vector<float>>& data,
const std::vector<float>& totals)
{
for (auto& v : data)
{
for (auto& v2 : v)
std::cout << v2 << " ";
std::cout << "\n";
}
std::cout << "Total: ";
for (auto& t : totals)
std::cout << t << " ";
}
int main()
{
std::vector<std::vector<float>> test1 = {{1,2,3},{4,5,6},{7,8,9}};
std::vector<std::vector<float>> test2 = {{1,2,3,4},{4,5,6,8},{7,8,9,10}};
std::vector<std::vector<float>> test3 = {{1,2},{-3,4},{7,8},{34,12},{12,17}};
printTotals(test1, getTotals(test1));
std::cout << "\n\n";
printTotals(test2, getTotals(test2));
std::cout << "\n\n";
printTotals(test3, getTotals(test3));
}
Output:
1 2 3
4 5 6
7 8 9
Total: 12 15 18
1 2 3 4
4 5 6 8
7 8 9 10
Total: 12 15 18 22
1 2
-3 4
7 8
34 12
12 17
Total: 51 43
Once you have this, the next step is to create the std::vector<std::vector<float>> from the data in the file. Once that is created, it is just a simple matter of calling the getTotals() function with that data.
The file reading can be as follows:
#include <istream>
#include <sstream>
#include <vector>
#include <string>
//...
std::vector<std::vector<float>> readData(std::istream& is)
{
std::vector<std::vector<float>> data;
std::string oneLine;
float oneData;
while (std::getline(is, oneLine))
{
std::vector<float> vOneData;
std::istringstream strm(oneLine);
while (strm >> oneData)
vOneData.push_back(oneData);
data.push_back(vOneData);
}
return data;
}
The function is called by simply passing in the stream object (in your case, myfile). The returned value will be a std::vector<std::vector<float>> of the values that were read in.
Putting this all together:
#include <vector>
#include <numeric>
#include <iostream>
#include <istream>
#include <string>
#include <sstream>
std::vector<float> getTotals(const std::vector<std::vector<float>>& myData)
{
std::vector<float> totals(myData[0].size());
for (size_t i = 0; i < totals.size(); ++i)
{
totals[i] = std::accumulate(myData.begin(), myData.end(), 0,
[&](int total, auto& v)
{ return total + v[i]; });
}
return totals;
}
void printTotals(const std::vector<std::vector<float>>& data,
const std::vector<float>& totals)
{
for (auto& v : data)
{
for (auto& v2 : v)
std::cout << v2 << " ";
std::cout << "\n";
}
std::cout << "Total: ";
for (auto& t : totals)
std::cout << t << " ";
}
std::vector<std::vector<float>> readData(std::istream& is)
{
std::vector<std::vector<float>> data;
std::string oneLine;
float oneData;
while (std::getline(is, oneLine))
{
std::vector<float> vOneData;
std::istringstream strm(oneLine);
while (strm >> oneData)
vOneData.push_back(oneData);
data.push_back(vOneData);
}
return data;
}
int main()
{
std::string fileData = "2 3 4 1 5 2\n6 1 2 6 1 8\n8 7 3 9 6 4";
std::istringstream fileDataStream(fileData);
auto dataFromFile = readData(fileDataStream);
printTotals(dataFromFile, getTotals(dataFromFile));
}
Output:
2 3 4 1 5 2
6 1 2 6 1 8
8 7 3 9 6 4
Total: 16 11 9 16 12 14
Note that I didn't use a file stream, but a stringstream to illustrate it doesn't matter how the data is created.
So I'm unable to create a substring cut using ranges. I am making an airport program where you feed the program a txt.file and it has to divide the lines I get from it into different strings. For instance, I have the following text data:
CL903 LONDON 41000 14.35 08906 //number of flight, destination, price, etc.
UQ5723 SYDNEY 53090 23.20 12986
IC5984 TORONTO 18030 04.45 03260
AM608 TOKYO 41070 18.45 11315
so the first string will be on the lines of this (variables are in Spanish):
numVuelo[n] = M[n].substr(0,5)
this line will work perfectly, but when I move to the next one (from 7 to 14), it tells me that it's out of range, even though It's between the 0 and 31st values of the length of the string.
M[n] gets all of the strings on the text, I'm using Codeblocks and a class style with header and all. I'll copy the code below...
This is my header Vuelo.h:
#ifndef VUELO_H
#define VUELO_H
#include <iostream>
#include <fstream>
#include <string>
#define NUM_FLIGHTS 10
using namespace std;
class Vuelo
{
public:
Vuelo(int N);
virtual ~Vuelo();
void setM();
void setNumVuelo(string _numVuelo, int n);
void setDestino(string _destino, int n);
void setPrecio(string _precio, int n);
private:
string M[NUM_FLIGHTS];
string numVuelo[NUM_FLIGHTS];
string destino[NUM_FLIGHTS+1]; //somehow "destino" doesn't work without the +1 but everything else does
float precio[NUM_FLIGHTS];
Then, on another code called Vuelo.cpp I have the following
#include "Vuelo.h"
Vuelo::Vuelo(int N)
{
M[N] = { };
numVuelo[N] = { };
destino[N] = { };
precio[N] = { };
}
Vuelo::~Vuelo()
{
//nope
}
void Vuelo::setM()
{
int c = 1;
string s;
ifstream F ("flights.txt");
if(F.is_open())
{
while (!F.eof())
{
getline(F,s);
M[c] = s;
cout << M[c] << endl;
c++;
}
//sets all values
for(c = 0; c < NUM_FLIGHTS; c++)
{
setNumVuelo(M[c],c);
setDestino(M[c],c);
setPrecio(M[c],c);
}
F.close();
}
else
{
cout << "ERROR document wasn't found" << endl;
}
}
void Vuelo::setNumVuelo(string _numVuelo, int n)
{
numVuelo[n]= _numVuelo.substr(0,5); //this works
cout << numVuelo[n] <<endl;
}
void Vuelo::setDestino(string _destino, int n)
{
destino[n] = _destino.substr(7, 13); //PROBLEM HERE
cout << destino[n] << " " << destino[n].length() << endl;
}
void Vuelo::setPrecio(string _precio, int n)
{
string p = _precio.substr(15,19); //PROBLEM HERE
precio[n] = atof(p.c_str());
cout << precio[n] <<endl;
}
And finally my main looks like this:
#include "Vuelo.h"
#include <iostream>
#include <fstream>
#include <string>
#define NUM_FLIGHTS 10
using namespace std;
int main()
{
cout << "Bienvenido, reserva tu vuelo!" << endl;
cout << "-----------------------------------" << endl;
Vuelo* flight = new Vuelo(NUM_FLIGHTS);
flight->setM();
return 0;
}
Thanks :)
I am trying to use c++ to sum 3 integers from the input, but I keep get 0. Please help thx.
vector<int> x;
x.reserve(3);
cin >> x[0] >> x[1] >> x[2];
int sum = std::accumulate(x.begin(), x.end(), 0);
cout << sum << endl;
return 0;
1
2
3
0
vector::reserve(size_type n) will request a change in the capacity of the vector, not the size. You can use the resize function, or even better the constructor.
int main()
{
std::vector<int> x(3,0); //set the size to 3 and fill with zeros.
std::cin >> x[0] >> x[1] >> x[2];
int sum = std::accumulate(x.begin(), x.end(), 0);
std::cout << sum << std::endl;
}
You can read this answer here for the differences between reserve vs resize.
Fill your vector first with something if not you will probably get undefined
vector<int> x(3,0);
use c++ to sum 3 integers from the input
why accumulate always return 0
This answer uses push_back(), and does not need to know how many integers are input, as the vector will auto expand; In this way it sidesteps the issues of std::vector that were defeating your code.
Consider that, because a "how many int" might be submited is seldom fixed you are more likely to want to count how many input "on the fly". So perhaps use a loop, cin to a local var, then x.push_back( a_local_var), and repeat until some condition (maybe eof(), or local var == -1, etc.) x.size() is your counter.
Here is a functioning example, using command line vars and eof() (and a vector and accumulate).
// Note: compile with -std=c++17 for the using comma list
#include <iostream>
using std::cout, std::cerr, std::endl, std::hex, std::dec, std::cin, std::flush; // c++17
#include <vector>
using std::vector;
#include <string>
using std::string;
#include <sstream>
using std::stringstream;
#include <numeric>
using std::accumulate;
#include <cassert>
class T951_t // ctor and dtor compiler provided defaults
{
public:
int operator()(int argc, char* argv[]) { return exec(argc, argv); } // functor entry
private:
stringstream ssIn; // to simulate user input
int exec(int argc, char* argv[])
{
int retVal = initTest(argc, argv); // transfer command line strings into ssIn
if(retVal != 0) return retVal;
// ------------------------------------------------------------
// simulate unknown quantity of ints
vector<int> x;
do {
int localInt = 0;
ssIn >> localInt;
if(!ssIn.good()) // was transfer ok?
{ // no
if (ssIn.eof()) break; // but we tolerate eof
// else err and exit
cerr << "\n !ssIn.good() failure after int value "
<< x.back() << endl;
assert(0); // harsh - user typo stops test
}
x.push_back(localInt); // yes transfer is ok, put int into vector
//cout << "\n " << localInt; // diagnostic
} while(true);
showResults(x);
return 0;
}
// this test uses a stringstream (ssIn) to deliver input to the app
// ssIn is initialized from the command line arguments
int initTest(int argc, char* argv[])
{
if (argc < 2) {
cerr << "\n integer input required" << endl;
return -1;
}
// test init
for (int i=1; i < argc; ++i) {
// cout << "\n " << argv[i]; // diagnostic
ssIn << argv[i] << " "; // user text into stream
}
cout << endl;
return 0;
}
// display size and contents of vector x
void showResults(vector<int> x)
{
cout << "\n x.size(): " << x.size() << endl;
int sum = std::accumulate(x.begin(), x.end(), 0);
for (auto i : x)
cout << " " << i;
cout << endl;
cout << "\n sums to: " << sum << '\n' << endl;
}
}; // class T951_t
int main(int argc, char* argv[]) { return T951_t()(argc, argv); } // call functor
Tests:
./dumy951 1 2 3 55 12345678900 <-- fail after 55 because last int too big
./dumy951 1 2 3 y 55 12345678900 <-- fail after int value 3 (invalid int)
./dumy951 1 2 3 4 5 6 7 8 9 10 <-- success, result is 55
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This code is supposed to read in from a file and store the information. Here's the file:
5
Franks,Tom 2 3 8 3 6 3 5
Gates,Bill 8 8 3 0 8 2 0
Jordan,Michael 9 10 4 7 0 0 0
Bush,George 5 6 5 6 5 6 5
Heinke,Lonnie 7 3 8 7 2 5 7
right now I'm just focused on saving pointers to the names. Here's the code I have so far (Ignore the other functions I haven't gotten to those yet). I have to save the names using employees[row] = new Employee; and fin >> employees[row]->names; and I just don't know how to go about doing that.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
struct Employee {
string names;
vector<int> data;
int totalHrs;
};
int fillAndTotal(vector<Employee *>&employees);
void sort(vector<Employee *>&employees, int amount);
void output(vector<Employee *>&employees, int amount);
int main()
{
vector<Employee *>employees;
//vector<string>names;
int amount = 0;
amount = fillAndTotal(employees);
sort(employees, amount);
output(employees, amount);
system("pause");
return 0;
}
int fillAndTotal(vector<Employee *>&employees) {
int const TTL_HRS = 7;
ifstream fin;
fin.open("empdata.txt");
if (fin.fail()) {
cout << "ERROR";
}
int sum = 0;
int numOfNames;
fin >> numOfNames;
string tmpString;
int tempInt = 0;
vector<int>temp(8);
for (int row = 0; row < numOfNames; row++) {
employees[row] = new Employee;
fin >> employees[row]->names;
Firstly, you don't need pointers for this - your Employee structure is perfectly safe to store as-in in a vector.
Secondly, when reading line-orientated data like this, it's very easy to get off-track and let your reads overflow into the next line, or underflow and you not carry out enough reads for the line - what I do is write a function that reads a whole line at a time and returns a stringstream containing just that line, then I do my individual reads on that stringstream.
Thirdly, and finally, it's always useful to write functions that allows you to dump out your data structures so that you can confirm visually that you've populated the structures correctly. Or you can use a debugger.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
struct Employee
{
std::string names;
std::vector<int> data;
int totalHrs;
};
using EmpList = std::vector<Employee>;
int fillAndTotal(EmpList& employees);
std::stringstream readRowData(std::istream& fin);
#ifndef NDEBUG
// Debug - dump to stream.
std::ostream& operator<<(std::ostream& out, const Employee& employee);
std::ostream& operator<<(std::ostream& out, const EmpList& employees);
#endif
int main(int argc, char* argv[])
{
EmpList employees;
auto grandTotal = fillAndTotal(employees);
std::cout << employees;
std::cout << "\nGrand total hours: " << grandTotal << std::endl;
}
int fillAndTotal(EmpList& employees)
{
auto fin = std::ifstream("empdata.txt");
auto rowCount = 0;
auto rowData = readRowData(fin);
rowData >> rowCount;
auto totalHours = 0;
for (auto i = 0; i < rowCount; ++i)
{
rowData = readRowData(fin);
if (!fin.eof())
{
auto employee = Employee{};
rowData >> employee.names;
int hours;
while (rowData >> hours)
{
if (hours != 0)
{
employee.data.push_back(hours);
employee.totalHrs += hours;
totalHours += hours;
}
}
employees.push_back(employee);
}
}
return totalHours;
}
std::stringstream readRowData(std::istream& fin)
{
std::stringstream rowStream;
std::string rowData;
if (getline(fin, rowData))
{
rowStream.str(rowData);
}
return rowStream;
}
#ifndef NDEBUG
std::ostream& operator<<(std::ostream& out, const Employee& employee)
{
out << "Name: " << employee.names << '\n';
out << "Total hours: " << employee.totalHrs << '\n';
out << "Individual hours:";
for (auto const &hours : employee.data)
{
out << ' ' << hours;
}
out << std::endl;
return out;
}
std::ostream& operator<<(std::ostream& out, const EmpList& employees)
{
auto first = true;
for (auto const &employee : employees)
{
if (first)
{
first = false;
}
else
{
out << '\n';
}
out << employee;
}
return out;
}
#endif
Now your output function is already written for you, and you just need to write your sort.
i am creating a somekind of rpg battle, where the program reads the input from a .txt file. i created the code but when i want to start the battle, it gave me an error vector subscript out of range. can anyone help me how to fix this? thank you very much :) here is the code. I included everything just so you could get a full context but the main problem I believe is in my while loop in the main cpp, if you want to just skip down to there.
and so that we are on the same track, the content of the txt file for lamanite(hitpoints and regen points) is
8 2
7 3
6 1
for nephite its
10 3
12 4
11 5
here is my warrior.h file
#pragma once
#include <string>
using namespace std;
class warrior
{
public:
warrior ();
warrior (int h, int r);
int getDamage() const;
void takeDamage(int damage);
int getCurrentHP() const;
void regenerate();
string tostring(int h, int r);
private:
int HitPoints;
int RegPoints;
int damage;
};
here is my warrior cpp
#include "warrior.h"
#include <string>
#include <iostream>
warrior::warrior(int h, int r)
{
HitPoints = h;
RegPoints = r;
}
int warrior::getDamage() const
{
int damage = rand () % HitPoints;
return damage;
}
void warrior::takeDamage(int damage)
{
HitPoints = HitPoints - damage;
}
int warrior::getCurrentHP() const
{
return HitPoints;
}
void warrior::regenerate()
{
HitPoints = HitPoints + rand () % (RegPoints);
}
string warrior::tostring(int h, int r)
{
return 0;
}
my main file
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include "warrior.h"
using namespace std;
void main ()
{
srand(time(0));
ifstream input1;
cout << "input file name nephite: ";
string filename;
cin >> filename;
input1.open(filename);
int HP1, RP1;
vector <warrior*> nephites;
while (input1 >> HP1 >> RP1)
{
nephites.push_back(new warrior(HP1, RP1));
}
cout << nephites.size() << endl;
ifstream input2;
cout << "input file name lamanite : ";
string filename2;
cin >> filename2;
input2.open(filename2);
int HP2, RP2;
vector <warrior*> lamanites;
while (input2 >> HP2 >> RP2)
{
lamanites.push_back(new warrior(HP2, RP2));
}
cout << lamanites.size() << endl;
cout << endl << "Battle" << endl;
warrior nephitesw = warrior (HP1,RP1);
warrior lamanitesw = warrior (HP2,RP2);
while ((nephites.size() > 0) && (lamanites.size() > 0))
{
int rN = rand () % nephites.size();
int rL = rand () % lamanites.size();
cout << rN << "xx" << rL << endl; // so that i know what rN and rL is
while((nephites[rN]->getCurrentHP() > 0) && (lamanites[rL]->getCurrentHP() > 0)) // the program can't execute this part of the code
{
nephites[rN]->takeDamage(lamanites[rL]->getDamage());
lamanites[rL]->takeDamage(nephites[rN]->getDamage());
if(lamanites[rL]->getCurrentHP() > 0)
{
lamanites[rL]->regenerate();
}
else
{
lamanites.erase(lamanites.begin() + (rL));
}
if(nephites[rN]->getCurrentHP() > 0)
{
nephites[rN]->regenerate();
}
else
{
nephites.erase(nephites.begin() + (rN));
}
}
cout << "NEP HP: " << nephites[rN]->getCurrentHP() << " " << "LAM HP: " << lamanites[rL]->getCurrentHP() << endl;
}
system ("Pause");
}
You have a while loop that tests for a certain properties of nephites[rN] and lamanites[rL]:
while((nephites[rN]->getCurrentHP() > 0) && (lamanites[rL]->getCurrentHP() > 0)
{
// ...
}
But inside that loop you might erase those elements:
{lamanites.erase(lamanites.begin() + (rL));}
// ...
{nephites.erase(nephites.begin() + (rN));}
At the very least, after one of those erase operations you'll be testing a different nephite or lamanite object on the next loop iteration (which may or may not be what you want), but if you've erased the last element in the container, you have the problem that the index is now out of range.
You are looping until either nephites[rN]->getCurrentHP() <= 0 or lamanites[rL]->getCurrentHP() <= 0. However, whichever one drops to 0 first will be deleted from the vector:
// ...
{lamanites.erase(lamanites.begin() + (rL));}
// ...
{nephites.erase(nephites.begin() + (rN));}
If rN == nephites.size() or rN == lamanites.size() (which will definitely happen when the size is 1 and may randomly happen earlier), this will cause you to index out of the vector when you test the loop.
To quickly solve the problem, move the code that removes the warrior(s) from the vector out of the loop:
while((nephites[rN]->getCurrentHP() > 0) && (lamanites[rL]->getCurrentHP() > 0))
{
nephites[rN]->takeDamage(lamanites[rL]->getDamage());
lamanites[rL]->takeDamage(nephites[rN]->getDamage());
if(lamanites[rL]->getCurrentHP() > 0)
{
lamanites[rL]->regenerate();
}
if(nephites[rN]->getCurrentHP() > 0)
{
nephites[rN]->regenerate();
}
}
cout << "NEP HP: " << nephites[rN]->getCurrentHP() << " " << "LAM HP: " << lamanites[rL]->getCurrentHP() << endl;
// *****
// Move the erasures out of the loop
// *****
if(lamanites[rL]->getCurrentHP() <= 0)
{
lamanites.erase(lamanites.begin() + (rL));
}
if(nephites[rN]->getCurrentHP() <= 0)
{
nephites.erase(nephites.begin() + (rN));
}