Dec 11, 2016 at 12:59am UTC
i'm new too programming and i can't get it too add levels too track experience and increase levels
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
// Tracks Exp
int static experience = 0;
// Tracks Player Level
int static playerLevel = 0;
// Adds Exp
int static addExperience(int addExp)
{
experience = experience + addExp;
return experience;
}
// Negates Exp??
int negateExperience(int negExp)
{
experience = experience - negExp;
return experience;
}
// Program start
int main()
{
// sad attempt at adding levels based on experience
void addLevel();
{
static const int reqExp[] =
{
0, 45, 90, 150, 250, 500
};
while (experience >= reqExp[playerLevel])
++playerLevel;
return;
}
// test to track if experience and levels are working
string Questions;
int questionOne;
int questionOneAnswer = 8;
cout << "What is 5 + 3? ";
cin >> questionOne;
//if correct answer
if (questionOne == questionOneAnswer)
{
cout << "Correct!" << endl;
addExperience(90);
addLevel();
cout << "+ 45 Experience!" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if(questionOne > questionOneAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel();
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if(questionOne < questionOneAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel();
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
//keeps window open
int x;
cin >> x;
return 0;
}
Last edited on Dec 11, 2016 at 1:06am UTC
Dec 11, 2016 at 1:15am UTC
thank you for your assistance it helped me complete the code to split the two im sorry for such a noob mistake XD
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
// Tracks Exp
int static experience = 0;
// Tracks Player Level
int static playerLevel = 0;
// Adds Exp
int static addExperience(int addExp)
{
experience = experience + addExp;
return experience;
}
// Negates Exp??
int negateExperience(int negExp)
{
experience = experience - negExp;
return experience;
}
// Program start
int main()
{
// sad attempt at adding levels based on experience
static const int reqExp[] =
{
0, 45, 90, 150, 250, 500
};
int static addLevel;
{
while (experience >= reqExp[playerLevel])
++playerLevel;
};
// test to track if experience and levels are working
string Questions;
int questionOne;
int questionOneAnswer = 8;
cout << "What is 5 + 3? ";
cin >> questionOne;
//if correct answer
if (questionOne == questionOneAnswer)
{
cout << "Correct!" << endl;
addExperience(90);
addLevel;
cout << "+ 45 Experience!" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if(questionOne > questionOneAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel;
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if(questionOne < questionOneAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel;
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
//keeps window open
int x;
cin >> x;
return 0;
}
Last edited on Dec 11, 2016 at 1:25am UTC
Dec 11, 2016 at 1:41am UTC
maybe im doing something wrong but when i do
addLevel();
it creates an error
because my new method is
int static addLevel;
{
while (experience >= reqExp[playerLevel])
++playerLevel;
};
if i change it too
int static addLevel()
{ <--- error here
while (experience >= reqExp[playerLevel])
++playerLevel;
};
then it error's my while loop next too arrow
i just started coding about 2 weeks ago and i havent gotten it all down fully but i would like to believe i am progressing well considering the only code not my own was add level i had looked that up which was still wrong lol but the problem i am running into now is i created a question 2 with exp and it goes up +1 level on question 1 but not on question 2 with 200 exp
Dec 11, 2016 at 2:34am UTC
i fixed the issue and will post the code for others too see thank you for your assitance
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
#include <iostream>
#include <string>
#include <sstream>
#include <Windows.h>
using namespace std;
// Tracks Exp
int static experience = 0;
// Tracks Player Level
int static playerLevel = 1;
// Uses array to store required exp too level
static const int reqExp[] =
{
0, 45, 90, 150, 250, 500
};
// uses reqExp[playerLevel] to check required exp example : Level 0 = 0exp level 1 = 45...
int addLevel()
{
while (experience >= reqExp[playerLevel])
++playerLevel;
return playerLevel;
};
// Adds Exp
int static addExperience(int addExp)
{
experience = experience + addExp;
return experience;
}
// Negates Exp??
int negateExperience(int negExp)
{
experience = experience - negExp;
return experience;
}
// Program start
int main()
{
// test to track if experience and levels are working
string Questions;
int questionOne;
int questionOneAnswer = 8;
cout << "Question 1" << endl;
cout << "What is 5 + 3? " ;
cin >> questionOne;
//if correct answer
if (questionOne == questionOneAnswer)
{
cout << "Correct!" << endl;
addExperience(100);
addLevel();
cout << "+ 100 Experience!" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if (questionOne > questionOneAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel();
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if (questionOne < questionOneAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel();
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
int questionTwo;
int questionTwoAnswer = 19;
cout << "Question #2" << endl;
//Question 2
cout << "What is 8 + 11? " ;
cin >> questionTwo;
//if correct answer
if (questionTwo == questionTwoAnswer)
{
cout << "Correct!" << endl;
addExperience(100);
addLevel();
cout << "+ 100 Experience!" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if (questionTwo > questionTwoAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel();
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
// if wrong answer
else if (questionTwo < questionTwoAnswer)
{
cout << "Incorrect" << endl;
negateExperience(20);
addLevel();
cout << "-20 Experience" << endl;
cout << "Total Experience = " << experience << endl;
cout << "Player Level = " << playerLevel << endl;
}
//keeps window open
int x;
cin >> x;
return 0;
}
Last edited on Dec 11, 2016 at 2:35am UTC