I'm creating a text-based adventure game but I've come up with an error.
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <random>
#include <ctime>
#include <cctype>
#include <ctype.h>
#include "bits/stdc++.h"
#include <list>
using namespace std;
string Darkvision = "Darkvision: The ability to see far within the shadows";
string Giantfoe = "Giantfoe: The skill to bring down colossal beasts";
vector<string> abilites;
list<string> raceChoiceList = {};
list<string>::iterator it = raceChoiceList.begin();
list<string> yesList = {"Y","Y.","YES","YES."}; list<string>::iterator yes = yesList.begin();
list<string> noList = {"N","N.","NO","NO."}; list<string>::iterator no = noList.begin();
bool raceChoiceHuman = false;
bool raceChoiceDwarf = false;
bool raceChoiceElf = false;
string yesNoInput;
int bugFixer1 = 0; int yesNoOut;
int Die(int sides, int minVal) {
srand((unsigned int) time(NULL));
int roll = (rand() % sides) + minVal;
return roll;
}
string printVector(auto vectorName) {
for (int i = 0; i < vectorName.size(); i++) {
cout << vectorName[i] << "\n";
}
}
string findElement(auto vectorName, string Element) {
string element;
auto itr = find(Element.begin(), Element.end(), element);
if (itr != Element.end()) {
cout << "You have the ability of " << element << "\n";
} else {
cout << "You do not have the ability of " << element << "\n";
}
}
class Player {
public:
int d6_1;
int d6_2;
int d6_3;
int d6_4;
int d6_5;
int d6_6;
double pi = 2 * acos(0.0);
string playerClass;
string name;
string race;
string size;
int strength = Die(18, 3);
int dexterity = Die(18, 3);
int constituion = Die(18, 3);
int intelligence = Die(18, 3);
int wisdom = Die(18, 3);
int charisma = Die(18, 3);
int strMod;
int dexMod;
int conMod;
int wisMod;
int intMod;
int chaMod;
string meleeWeapon = "fists";
string rangedWeapon;
string magic;
void statMods() {
strMod = floor((strength - 10) / 2);
dexMod = floor((dexterity - 10) / 2);
conMod = floor((constituion - 10) / 2);
wisMod = floor((wisdom - 10) / 2);
intMod = floor((intelligence - 10) / 2);
chaMod = floor((charisma - 10) / 2);
}
};
class Item {
public:
string effect;
};
class Weapon: public Item {
public:
string material;
string enchantment;
};
class Sword: public Weapon {
public:
int dmg;
string dmgType;
};
class Dice {
public:
int sides;
int Roll(int times){
int rolls;
srand(time(NULL)); for (int i = 0; i < times; i++){
int roll_; roll_ = rand() % sides + 1; rolls += roll_;
}
return rolls;
}
};
void toupper(std::string &stri) {
if (stri.length() == 0) {
return;
}
transform(begin(stri), end(stri), begin(stri), [](char const &c) {
return tolower(c);
});
int counter = 0;
for (char letter : stri){
stri[counter] = toupper(stri[counter]);
counter += 1;
}
}
int yesNo(){ string yesNoChoice = "aaa";
getline(cin, yesNoChoice);
getline(cin, yesNoChoice);
toupper(yesNoChoice);
stringstream s(yesNoChoice);
string word;
while (s >> word){
for (string option : yesList){
if (word == option){
cout << "Press enter to continue. \n>";
return 1;
}
for (string option : noList){
if (word == option){
return 0;
}
}
}
}
return 2;
}
int main() {
Dice D6;
D6.sides = 6;
Player player1;
player1.statMods();
Weapon Torch;
Torch.effect = "light";
Torch.material = "wood";
Item inventory[10] = {Torch};
cout << "What is your name, traveler?" << "\n";
bool nameRestart = true;
while (nameRestart) {
cout << "> ";
cin >> player1.name;
cout << player1.name << "? Are you sure that's your true name?" << "\n";
cout << "> ";
yesNoOut = yesNo();
if (yesNoOut == 1) {
nameRestart = false;
}
}
bool raceRestart = true;
while (raceRestart) {
raceRestart = false;
if (bugFixer1 == 1){
cout << "Where do you hail from " << player1.name << "?" << "\n";
cout << "The Human Cities? Perhapes the Elven Forests? or the Mightly Dwarven Kingdoms?" << "\n";
cout << "> ";
}
string raceChoice;
getline (cin, raceChoice);
toupper(raceChoice);
stringstream ss(raceChoice);
string word;
while (ss >> word) {
if (word == "ELF" || word == "ELF." || word == "FOREST" || word == "FOREST."|| word == "FORESTS" || word == "FORESTS." || word == "ELVEN" || word == "ELVEN."){
raceChoiceElf = true;
} else if (word == "DWARF" || word == "DWARF." || word == "KINGDOM" || word == "KINGDOM."|| word == "KINGDOMS" || word == "KINGDOMS." || word == "DWARVEN" || word == "DWARVEN."){
raceChoiceDwarf = true;
} else if (word == "HUMAN" || word == "HUMAN." || word == "CITY" || word == "CITY."|| word == "CITIES" || word == "CITIES."){
raceChoiceHuman = true;
}
}
if (raceChoiceHuman) {
player1.race = "Human";
player1.strength++;
player1.dexterity++;
player1.constituion--;
player1.wisdom--;
player1.intelligence--;
player1.charisma++;
player1.size = "M";
break;
} else if (raceChoiceElf) {
player1.race = "Elf";
player1.strength--;
player1.strength--;
player1.dexterity++;
player1.dexterity++;
player1.constituion--;
player1.wisdom++;
player1.size = "M";
abilites.push_back(Darkvision);
break;
} else if (raceChoiceDwarf) {
player1.race = "Dwarf";
player1.strength++;
player1.strength++;
player1.dexterity--;
player1.dexterity--;
player1.constituion++;
player1.charisma--;
player1.size = "M";
abilites.push_back(Darkvision);
break;
} else {
if (bugFixer1 == 0){
bugFixer1 = 1;
raceRestart = true;
} else {
cout << "Invalid command" << "\n";
raceRestart = true;
}
}
}
cout << "Hmm, so you are a " << player1.race << "?" << "\n";
string raceCheck;
cin >> raceCheck;
toupper(raceCheck);
player1.statMods();
if (raceCheck == "No") {
raceRestart = true;
} else {
cout << "Race:" << player1.race << "\n" << "Strength: " << player1.strength << "\n" << "Dexterity: " << player1.dexterity << "\n" << "Constitution: " << player1.constituion << "\n" << "Wisdom: " << player1.wisdom << "\n" << "Intelligence: " << player1.intelligence << "\n" << "Charisma: " << player1.charisma << "\n" << "Size: " << player1.size << "\n" << player1.strMod << "\n" << player1.dexMod << "\n" << player1.conMod << "\n" << printVector(abilites);
}
}
Everytime I run it I get this:
main.cpp:49:20: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
49 | string printVector(auto vectorName) {
| ^~~~
main.cpp: In function ‘std::string printVector(auto:1)’:
main.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
53 | }
| ^
main.cpp: At global scope:
main.cpp:55:20: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
55 | string findElement(auto vectorName, string Element) {
| ^~~~
main.cpp: In function ‘std::string findElement(auto:2, std::string)’:
main.cpp:63:1: warning: no return statement in function returning non-void [-Wreturn-type]
63 | }
| ^
What is your name, traveler?
> ph
ph? Are you sure that's your true name?
> yes
Press enter to continue.
>
Where do you hail from ph?
The Human Cities? Perhapes the Elven Forests? or the Mightly Dwarven Kingdoms?
> elf
Hmm, so you are a Elf?
yes
Race:Elf
Strength: 13
Dexterity: 17
Constitution: 14
Wisdom: 16
Intelligence: 15
Charisma: 15
Size: M
1
3
2
Darkvision: The ability to see far within the shadows
free(): invalid size
Aborted (core dumped)
If anyone could help me It would be much appreciated.
Note: I'm new to C++ so I'm attempting to inform myself on the language and various concepts in the field. I apologize in advance for the most likely horrendous code.
What I have tried:
Spending the last 3 hours of my life trying to figure this out.