Incomplete Character genetor program

All right I'm working on a project for school and I have most of it working but I don't know how to get this last part working. I'd ask the teacher but he's away to a seminar or something for the next 3 days. The whole assignement is this:
 Each character has a name, a profession (either Scholar, Knight, Parson or Rogue), experience points and a level.
 Prompt the user to make exactly 3 characters. For each character the user must enter a name, select a profession, and enter the number or experience points a character has.
 Limit the user to just one of the 4 possible profession.
 Calculate the level for each character, with level 20 being the maximum
 Display the character information as shown below, in columns with the levels displayed as * characters (1 per level)
 Your program must have a menu display and an execution loop
 Pause before quitting or repeating.
 Clear the screen at the beginning of the menu
 User may choose to quit after seeing the characters, or start over
 Use a loop to get correct data for selecting a class
 Use a loop for printing the * characters for level

A character gets a level every 2000 experience points and begins at level 1. So 0-1999: level 1; 2000 -3999: level 2, etc.

Now I've done most of this and it all works but I need to make a menu that looks like this

Name Profession Level
---- ----- -----
charactername1 characterclass1 **********
charactername2 characterclass2 *********************
charactername3 characterclass3 ******

Were the number of * is the level of the character.

If anyone can give me some pointers as to how I can finish this program it would be really appreciated. Here is my code so far in case it helps.

#include <iostream>
#include <string>


using namespace std;

int main ()
{
//DECLARE VARIABLES
string charactername1;
string characterclass1;
string charactername2;
string characterclass2;
string charactername3;
string characterclass3;
string answer1;
string answer2;
string answer3;
int experience1;
int experience2;
int experience3;
int level1;
int level2;
int level3;

cout << "Welcome to Jamie's character generator\n";
cout << "You are going to need three characters each whit a profession and a starting level.";

//FIRST CHARACTER
cout << " Now lets begin your first character.\n";

do
{

cout << "What is your first character's name?\n";
getline (cin, charactername1);
if (answer1 == "no")
{
getline (cin, charactername1);
}

cout << "What is your first character's class?\n";

cout << " a) Scholar\n";
cout << " b) Knight\n";
cout << " c) Parson\n";
cout << " d) Rogue\n";

getline (cin, characterclass1);

if (characterclass1 == "a") cout << "So " << charactername1 << " is a scholar? Very well how much experience does he have?" ;
if (characterclass1 == "b") cout << "So " << charactername1 << " is a Knight? Very well how much experience does he have?" ;
if (characterclass1 == "c") cout << "So " << charactername1 << " is a Parson? Very well how much experience does he have?" ;
if (characterclass1 == "d") cout << "So " << charactername1 << " is a Rogue? Very well how much experience does he have?" ;

do {
cin >> experience1;

if (experience1 > 40000)
{
cout << "The maximum level is 20 you must enter enter an amount fo experience below 40000.\n" ;
}
}while (experience1 > 40000);

if (experience1 < 40000) ;
level1 = experience1/2000+1;

cout << " So then your first character is going to be " << charactername1 << " the " << level1;
if (characterclass1 == "a") cout << "th level Scholar.\n";
if (characterclass1 == "b") cout << "th level Knight.\n";
if (characterclass1 == "c") cout << "th level Parson.\n";
if (characterclass1 == "d") cout << "th level Parson.\n";

cout << " Is this correct? yes/no?\n";
cin >> answer1;

}

while (answer1 == "no");

//SECOND CHARACTER

do
{

cout << "What is your Second character's name?\n";
getline (cin, charactername2);
getline (cin, charactername2);

cout << "What is your second character's class?\n";

cout << " a) Scholar\n";
cout << " b) Knight\n";
cout << " c) Parson\n";
cout << " d) Rogue\n";

getline (cin, characterclass2) ;

if (characterclass2 == "a") cout << "So " << charactername2 << " is a scholar? Very well how much experience does he have?" ;
if (characterclass2 == "b") cout << "So " << charactername2 << " is a Knight? Very well how much experience does he have?" ;
if (characterclass2 == "c") cout << "So " << charactername2 << " is a Parson? Very well how much experience does he have?" ;
if (characterclass2 == "d") cout << "So " << charactername2 << " is a Rogue? Very well how much experience does he have?" ;

do {
cin >> experience2;

if (experience2 > 40000)
{
cout << "The maximum level is 20 you must enter enter an amount fo experience below 40000.\n" ;
}
}while (experience2 > 40000);

if (experience2 < 40000) ;
level2 = experience2/2000+1;

cout << " So then your first character is going to be " << charactername2 << " the " << level2;
if (characterclass2 == "a") cout << "th level Scholar.\n";
if (characterclass2 == "b") cout << "th level Knight.\n";
if (characterclass2 == "c") cout << "th level Parson.\n";
if (characterclass2 == "d") cout << "th level Parson.\n";

cout << " Is this correct? yes/no?\n";
cin >> answer2;
}
while (answer2 == "no");

//THIRD CHARACTER

do
{

cout << "What is your Third character's name?\n";
getline (cin, charactername3);
getline (cin, charactername3);

cout << "What is your Third character's class?\n";

cout << " a) Scholar\n";
cout << " b) Knight\n";
cout << " c) Parson\n";
cout << " d) Rogue\n";

getline (cin, characterclass3);

if (characterclass3 == "a") cout << "So " << charactername3 << " is a scholar? Very well how much experience does he have?" ;
if (characterclass3 == "b") cout << "So " << charactername3 << " is a Knight? Very well how much experience does he have?" ;
if (characterclass3 == "c") cout << "So " << charactername3 << " is a Parson? Very well how much experience does he have?" ;
if (characterclass3 == "d") cout << "So " << charactername3 << " is a Rogue? Very well how much experience does he have?" ;

do {
cin >> experience3;

if (experience3 > 40000)
{
cout << "The maximum level is 20 you must enter enter an amount fo experience below 40000.\n" ;
}
}while (experience3 > 40000);

if (experience3 < 40000) ;
level3 = experience3/2000+1;

cout << " So then your first character is going to be " << charactername3 << " the " << level3;
if (characterclass3 == "a") cout << "th level Scholar.\n";
if (characterclass3 == "b") cout << "th level Knight.\n";
if (characterclass3 == "c") cout << "th level Parson.\n";
if (characterclass3 == "d") cout << "th level Parson.\n";

cout << " Is this correct? yes/no?\n";
cin >> answer3;
}

while (answer3 == "no");

system ("pause");

return 0;
}



Last edited on
Maybe something like this:

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iostream>
//#include <string>
#include <sstream>
#include <Math.h>

using namespace std;

const string classname[4] = { "Scholar", "Knight", "Parson", "Rogue" };
const string num[4] = { "first", "second", "third", "fourth" };

class character {
    private:
        string name;
        int klass;
        int experience;
        int profession;
    public:
        character() {
            profession = 0;
        }
        ~character() { }

        void setname(string sN) { name = sN; }
        void setexp(int iE) { experience = iE; }
        void setclass(int iK) { klass = iK; }
        void setprof(int iP) { profession = iP; }

        void addexp(int iE) { experience += iE; }

        string getname() { return name; }
        int getclass() { return klass; }
        int getexp() { return experience; }
        int getprof() { return profession; }

        bool setup(int i);

        int level() {
            return (int)ceil(experience / 2000)+1;
        }
};



bool character::setup(int i = 1) {
    string temp;

    cout << "Now lets begin your " << num[i] << " character.\n\n";

    // Name
    cout << "What is your " << num[i] << " character's name? ";
    getline(cin, name);

    // Class
    cout << "\nWhat is your " << num[i] << " character's class?\n";
    for (int a = 0; a < 4; a++)
        cout << " " << char(97+a) << ") " << classname[a] << "\n";
    while(true) {
        getline(cin, temp);
        transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
        if (temp.length() == 1) {
            if ( (temp[0] > 96) && (temp[0] < 101) ) break;
        }
    }
    klass = temp[0] - 97;
    cout << "So " << name << " is a " << classname[klass] << ".\n";


    // Experience
    cout << "Very well how much experience does he have? ";
    while(true) {
        getline(cin, temp);
        stringstream myStream(temp);
        if (myStream >> experience) break;
        cout << "Enter a number. \n";
    }
    if (experience > 40000) experience = 40000;

    cout << "\n\nSo then your " << num[i] <<  " character is going to be " << name << " the level "
        << level() << " " << classname[klass] << ".\n";


    // Check
    cout << "Is this correct? ";
    while(true) {
        cout << "(yes/no) ";
        getline ( cin, temp);
        transform(temp.begin(), temp.end(), temp.begin(), ::tolower);

        if (temp == "no") {
            cout << "\n\n";
            return false;
        }
        if (temp == "yes") {
            cout << "\n\n";
            return true;
        }
    }
}

string fixlength(string s, int l) {
    string temp;

    if (s.length() > l) {
        temp = s.substr(0, l);
    } else {
        temp = s.append(l - s.length(), ' ');
    }
    return temp;
}

int main () {
    string temp;
    bool mainloop = true;

    character mychar[3];

    cout << "Welcome to Jamie's character generator\n";
    cout << "You are going to need three characters each with a profession and a starting level.\n\n";

    while (mainloop) {
        for (int i = 0; i < 3; i++)
            if (!mychar[i].setup(i)) i--;

        cout << "Characters: \n\n";
        cout << "Name           Profession     Level\n";
        cout << "-----------------------------------\n\n";
        for (int i = 0; i < 3; i++) {
            cout << fixlength(mychar[i].getname(), 14) << " ";
            cout << fixlength(classname[mychar[i].getprof()], 14);
            cout << "  " << mychar[i].level() << "\n";
        }

        while (true) {
            cout << "\n\n\nRepeat? (y/n)";
            getline(cin, temp);
            transform(temp.begin(), temp.end(), temp.begin(), ::tolower);

            if (temp.length() == 1) {
                if (temp[0] == 'y') break;
                if (temp[0] == 'n') { mainloop = false; break; }
            }
        }
        cout << "\n\n";
    }

    return 0;
}
Topic archived. No new replies allowed.