I have my loop set up as seen below:
#include <iostream>
#include <string>
#include <vector>
#include "Agent.h"
#include "Sage.h"
#include "Sova.h"
#include "Reyna.h"
using namespace std;
int main() {
int choice;
vector <Agent*> v;
do
{
cout << "Choose an Agent to Reveal Agent Ability" << endl;
cout << "---------------------------------------" << endl;
cout << "1. Sage" << endl;
cout << "2. Sova" << endl;
cout << "3. Reyna" << endl;
cout << "4. Display All" << endl;
cout << "5. Quit" << endl;
cin >> choice;
switch (choice)
{
case 1:
v.push_back(new Sage("Healing"));
break;
case 2:
v.push_back(new Sova("Sight"));
break;
case 3:
v.push_back(new Reyna("Blinding"));
break;
case 4:
v.push_back(new Sage("Healing"));
v.push_back(new Sova("Sight"));
v.push_back(new Reyna("Blinding"));
break;
default:
cout << "Bad choice! Please try again later.\n";
}
} while (choice <=0 || choice >=5);
for (const auto &Agent : v){
Agent->action();
}
return 0;
}
My condition is while (choice <=0 || choice >=5)
However, when I run this, after I make a choice, the information is output onto the screen and then the program ends. I tried other conditions, but when I selected a choice, the program will loop but will not output any information.
Is this a problem with the position for my for
loop?
for (const auto &Agent : v){
Agent->action();
}
Edit: Here's an example of the output I get when I use something like (choice != 5)
:
Choose an Agent to Reveal Agent Ability
---------------------------------------
1. Sage
2. Sova
3. Reyna
4. Display All
5. Quit
1
Choose an Agent to Reveal Agent Ability
---------------------------------------
1. Sage
2. Sova
3. Reyna
4. Display All
5. Quit
As you can see, it loops, but it does not display the output.