#include <iostream>
#include <cmath>
using namespace std;
//create the structure for a new class
struct NewClass
{
int level;
int Strength;
int Dexterity;
};
//prototype the function
int CharacterInfo( NewClass FistStats,int Clevel,int CStrength,int CDexterity);
//function for requesting user stats
int CharacterInfo(NewClass FistStats,int Clevel,int CStrength,int CDexterity)
{
//----------------------Character Level----------------------------------------
//prompt the user to input their character level
cout << "Enter your characters level(1-300)" << endl;
cin >> Clevel;
//Test wether their level is between 1 and 300
if(Clevel<1 || Clevel>300)
{ //do this if their level is not between 1-300
do
{
cout << "Enter your characters level(1-300)" << endl;
cin >> Clevel;
}while(Clevel<1 || Clevel>300);
}
//Create a variable for the total stat points relative to the player level
int TotalStatPoints = Clevel*10;
//-------------------------------Strength----------------------------------------
//display the Total stat points, ask the user wether they want to spend point in strength. If so, how many?
//store the value in Cstrength
cout << "You have " << TotalStatPoints << " free stat points" << endl;
cout << "How many stat points would you like to put into Strength?(0-" << TotalStatPoints << ")" << endl;
cin >> CStrength;
//Test wether the users input is less than 0 or greater than 1600
if(CStrength<0 || CStrength > TotalStatPoints)
{
//If so, then do this untill otherwise
do
{
cout << "You have " << TotalStatPoints << " free stat points" << endl;
cout << "How many stat points would you like to put into Strength?(0-" << TotalStatPoints << ")" << endl;
cin >> CStrength;
}while(CStrength<0 || CStrength > TotalStatPoints);
}
//----------------------------Remaining Stat Points-------------------------------
int RemainingStatPoints = TotalStatPoints - CStrength;
//--------------------------------Dexterity---------------------------------------
//Display a message telling the user the remaining stat points and allocate them to dexterity
cout << "The rest of your stat points will go into dexterity" << endl;
CDexterity = RemainingStatPoints;
//Display the amount of dex the person has
cout << "Your character has " << RemainingStatPoints << " dexterity" << endl;
//------------------------Display The Character Info-------------------------------
cout << "\nYour characters level is: " << Clevel << endl;
cout << "Your characters Strength is: " << CStrength << endl;
cout << "Your characters Dexterity is: " << CDexterity << endl;
return Clevel;
return CStrength;
return CDexterity;
}
int main()
{
//Create a structure along with the variable for the elements within that structure to pass into the
//Character info function
NewClass FistWarrior;
int Flevel;
int FStrength;
int FDexterity;
//use the Structure and variables above to pass into the CharacterInfo function
cout << CharacterInfo(FistWarrior, Flevel,FStrength,FDexterity);
system("pause");
return 0;
}
I want to pass the structure values from "int CharacterInfo(NewClass FistStats,int Clevel,int CStrength,int CDexterity)" to a new function that will use those structure values to calculate player damage.I will then return the damage value from the new function and display it in "int main()"
Heres the logic of the program:
function that takes user input for characters stats and stores it in a structure.
It then uses another function for calculating the damage value.
In the main body of code(int main), call from the functions.