Code runs but printing error.

Ok so I made this textdialougeTree. It suppose to print out the dialouge ,and choices. But I am getting nothing just press any key to continue. How come that is happening? Here is the code please help me find out what is going wrong. Please don't ask me what is exactly the problem if I knew i wouldn't be asking this question. It just prints nothing at all it runs with no errors whatsoever it just doesn't print anything.
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  #include <iostream>
#include <string>
#include <vector>
#include "DialougeTree.h"
//Battleships Game
//
using namespace std;
class Player1
{
public:
 Player1();
void SetHealth(int ThePlayerHealthis);
void SetMana(int ThePlayerManais);
void SetPlayerdamage(int ThePlayerdamageis);
int SetHealth();
int Setmana();
private:
int    Health = 0;
 int   Mana = 0;


};
Player1::Player1()
{
    Health = 100;
    Mana = 100;

}
 class Enemy
{
public:
    Enemy();
      virtual void TheenemyHealth(){}
     virtual int EnemyDamage(int EnemyAttack){
int  Attack = EnemyAttack;
     Attack = 15;
     return Attack;
    }
private:
   int Attackpower = 0;
    int Strenght = 0;


};
Enemy::Enemy()
{
    Attackpower;
    Strenght;

}
class Monster :public Enemy
{
    public:
    void TheenemyHealth()
    {
        int Enemyhealth = 100;
    }
    int EnemyDamage(int EnemyAttack){
    int Attack = EnemyAttack;
    Attack = 5;
    }


};


using namespace std;
int main()
{
    DialougeTree Dialouge;
    Dialouge.init();
    int rv = Dialouge.performdialouge();
    if (rv == 1)
    {
        cout << "You have accepeted the quest" << endl;

    }
 Dialouge.destorytree();
string tmp;
cout << "Press any key to continue " << endl;
cin >> tmp;


}

DialougeTree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef DIALOUGETREE_H
#define DIALOUGETREE_H
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class DialougeNode;
class DialougeOption

{
public:
    DialougeOption(string Text, int returncode,DialougeNode *NextNode);
    string text;
    DialougeNode *nextnode;
    int returnCode;
};
class DialougeNode
{
public:
    DialougeNode(string Text);
    string text;
    vector <DialougeOption> dialougeoptions;
};
using namespace std;
class DialougeTree
{
    public:
        DialougeTree();
        void init();
        void destorytree();
        int performdialouge();
    private:
        vector <DialougeNode *> dialougenodes;
};

#endif // DIALOUGETREE_H 

DialougeTree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "DialougeTree.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
DialougeNode::DialougeNode(string Text)
{
    Text=text;
}
DialougeOption::DialougeOption(string Text, int returncode,DialougeNode *NextNode)
{
    text = Text;
    returnCode = returncode;
    nextnode = NextNode;

}
DialougeTree::DialougeTree()
{
    //ctor
}
void DialougeTree::init()
{
    DialougeNode *node0 = new DialougeNode("Hello Brave warrior");
    DialougeNode *node1 = new DialougeNode("I don't want to talk to you");
    DialougeNode *node2 = new DialougeNode("I have a quest for you");
    DialougeNode *node3 = new DialougeNode("You will get paid greddy asshole");
    DialougeNode *node4 = new DialougeNode("Bring me 5 dandylions");

    //node0
    (*node0).dialougeoptions.push_back(DialougeOption("sup noob",0,node1));
     (*node0).dialougeoptions.push_back(DialougeOption("Hello strange voice",0,node2));

     dialougenodes.push_back(node0);
      //node1
     node1->dialougeoptions.push_back(DialougeOption("Aww",0,NULL));
     dialougenodes.push_back(node1);
     //node2
     node2->dialougeoptions.push_back(DialougeOption("K. Bye",0,NULL));
     node2->dialougeoptions.push_back(DialougeOption("What is it",0,node4));
     node2->dialougeoptions.push_back(DialougeOption("Whats the pay?",0,node3));
     dialougenodes.push_back(node2);

     //node3
       node3->dialougeoptions.push_back(DialougeOption("Ok what is it?",0,node4));
     node3->dialougeoptions.push_back(DialougeOption("that sucks im out",0,NULL));
       dialougenodes.push_back(node3);
     //node4
       node4->dialougeoptions.push_back(DialougeOption("Ok lets do it",1,NULL));
     node4->dialougeoptions.push_back(DialougeOption("Nope",0,NULL));
       dialougenodes.push_back(node4);
}
void DialougeTree::destorytree()
{
for (int i = 0; i < dialougenodes.size();i++)
{
    delete dialougenodes[i];
}
dialougenodes.clear();
}
int DialougeTree::performdialouge()
{
    if (dialougenodes.empty() == 0)
    {
        return -1;
    }
    DialougeNode *currentNode = dialougenodes[0];

    while(true)
{
    cout << currentNode->text << endl;
    cout << endl;
    for (int i = 0; i < currentNode->dialougeoptions.size(); i++)
        cout << i + 1 << ": " << currentNode->dialougeoptions[i].text << endl;
}
int input;
cin >> input;
input --;

if (input < 0 || input > currentNode->dialougeoptions.size())
{
    cout << "Invalid INput" << endl;
}
else{

if (currentNode ->dialougeoptions[input].nextnode == NULL)
{   return currentNode ->dialougeoptions[input].returnCode;

             }
       currentNode = currentNode ->dialougeoptions[input].nextnode;
        }
    }

AGAIN...Please don't ask "What is your question exactly". My question is to help find out whats wrong with my code. Its printing nothing from my DialougeTree nothing at all. Just printing "press any key to continue..."
Last edited on
One method of debugging is to add more "print" commands to various places to find out which paths does the execution follow.


Here, however, please re-read http://www.cplusplus.com/reference/vector/vector/empty/
Topic archived. No new replies allowed.