For some reason the program just skips the code after the point defining and just restarts the loop.
I cant find any reason for the program to do so so i hoped you could help me a little more...
Code:
#include <iostream>
#include <cstring>
#include <fstream>
#include <stdio.h>
int get_strlen(char * str)
{
int nbr = 0;
while (str[nbr] != '\0')
nbr++;
return nbr;
}
int main() {
char* filename;
int idx = 0;
int startoption;
char* saveoption;
char name[50];
int age;
char race[50];
char raceexample[10];
int classopt;
char* charclass;
char weapon;
int points;
points = 20;
int Str,Con,Int,Dex,Cha;
int strAdd,conAdd,intAdd,dexAdd,chaAdd;
int loopon;
loopon = 30;
while(loopon == 30){ //start loop
cout << "Hello and welcome to Daniel Bjorklunds RPG game.";
cout << "What would you want to do?\n";
cout << "1. Create a character\n";
cout << "2. Load an existing character\n";
cout << "3. Quit\n";
cin >> startoption;
switch(startoption) { //start switch
case 1:
cout << "\n-----CHARACTER CREATOR-----\n\n";
cout << "Choose a name for your character: ";
cin >> name;
cout << endl <<"You have chosen " << name << " as your character" << endl;
cout << "\n\aNext you need to choose an age for your character.\n";
cout << "The age depends upon your characters race (decided later).\n";
cout << "For example, humans can be from 15-50 while elves can be more than 2000 years old.\r";
cout << "Now choose an age: ";
cin >> age;
cout << endl <<"Your age is " << age << endl;
cout << "\n\aAnd now for the characters race.\n";
cout << "Choose whatever you want (within reasonable limits).\n";
cout << "\nExamples: Human, Elf, Dwarf, Goblin, Orc, Pixie\n";
cout << "Choose a race: ";
cin >> race;
cout << endl <<"Your race is " << race << endl;
cout << "Now for your characters class...\n";
cout << "Here are the classes you can choose from:\n\n";
cout << "1. Warrior, 2. Magician, 3. Ranger\n\n";
cout << "Now choose: ";
cin >> classopt;
if(classopt == 1) {
cout << endl << "You choose to be a Warrior!\n\n";
Str = 12;
Con = 12;
Int = 7;
Dex = 9;
Cha = 8;
charclass = "Warrior";
}
if(classopt == 2) {
cout << endl << "You choose to be a Magician!\n\n";
Str = 6;
Con = 8;
Int = 14;
Dex = 9;
Cha = 11;
charclass = "Magician";
}
if(classopt == 3) {
cout << endl << "You choose to be a Ranger!\n\n";
Str = 10;
Con = 10;
Int = 9;
Dex = 10;
Cha = 9;
charclass = "Ranger";
}
cout << "Now we are going to distribute some ability points.\n";
cout << "Right now your abilitys are:\n\n";
cout << "Strength (Str): " << Str;
cout << "\nConstitution (Con): " << Con;
cout << "\nDexterity (Dex): " << Dex;
cout << "\nIntelligence (Int): " << Int;
cout << "\nCharisma (Cha): " << Cha;
cout << "\n\nYou have " << points << " to distribute.\n";
cout << "You can only have a maximum of 18 points in each skill.\n\n";
cout << "Str: " << Str << " Points: " << points;
cout << "\n\nHow much would you like to add to your Strength?\n";
cout << "Add: ";
cin >> strAdd;
Str = Str + strAdd;
points = points - strAdd;
cout << endl << "Your Strength is now: " << Str << ".\n\n\n" << endl;
cout << "Con: " << Con << " Points: " << points;
cout << "\n\nHow much would you like to add to your Constitution?\n";
cout << "Add: ";
cin >> conAdd;
points = points - conAdd;
Con = Con + conAdd;
cout << endl << "Your Constitution is now: " << Con << ".\n\n\n" << endl;
cout << "Dex: " << Dex << " Points: " << points;
cout << "\n\nHow much would you like to add to your Dexterity?\n";
cout << "Add: ";
cin >> dexAdd;
Dex = Dex + dexAdd;
points = points - dexAdd;
cout << endl << "Your Dexterity is now: " << Dex << ".\n\n\n" << endl;
cout << "Int: " << Int << " Points: " << points;
cout << "\n\nHow much would you like to add to your Intelligence?\n";
cout << "Add: ";
cin >> intAdd;
Int = Int + intAdd;
points = points - intAdd;
cout << endl << "Your Intelligence is now: " << Int << ".\n\n\n";
cout << "Cha: " << Cha << " Points: " << points;
cout << "\n\nHow much would you like to add to your Charisma?\n";
cout << "Add: ";
cin >> chaAdd;
Cha = Cha + chaAdd;
points = points - chaAdd;
cout << endl << "Your Charisma is now: " << Cha;
cout << "\n\nDo you want to save this character?\n";
cin >> saveoption;
if(saveoption == "yes") {
filename = name;
idx = get_strlen(filename);
filename[idx] = '.';
filename[++idx] = 't';
filename[++idx] = 'x';
filename[++idx] = 't';
ofstream charfile(filename);
charfile << name << "\n";
charfile << age << "\n";
charfile << race << "\n";
charfile << charclass << "\n";
charfile << 1 << "\n";
charfile << 0 << "\n";
charfile << weapon << "\n";
charfile << Str << "\n";
charfile << Con << "\n";
charfile << Dex << "\n";
charfile << Int << "\n";
charfile << Cha;
charfile.close();
cout << "Your character has been succesfully saved in the file:\n\n";
cout << filename;
}
continue;
case 2:
cout << "That function is unavailable right now.\n\n";
continue;
case 3:
break;
}
break;
}
return 0;
}