   re-create class
  Fairly new to programming.  Less than 2 weeks.I'm just practicing, as practice makes perfect..The following code runs fine - no issues (on Linux anyway, I'm sure it's not cross platform lol - well maybe)...I started where I'm sure 99% of people start once they actually make their own programs instead of typing what a book tells them - a game.As a computer dork, I love D&D/AD&D, so thus why I went with this type of program.It asks for a name, then randoms values for health/str/dex/int/wis/cha(I didn't use d&d values :p.What I'm wanting to do, is give people the option of re-rolling if they're not happy with the rolls.. Issue I'm seeing is, all my function calls are in main.  I'm sure if I had main call a function that accomplished everything else, then put an if statement for re-rolling, I could just "yes" - recall function, "no" - don't.however, my question is, is there any way to do it with my calls being in the main function?  It'll be an easy fix to just move my entire main function to "create()" or whatever, and just call it from main, but after pondering the possibility, I'm just curious if it can be done...Please pardon the code if it's ugly - I'm still learning and it's not going to be very refined.Thanks in advance.#include <cstdlib>#include <cstdio>#include <iostream>#include <math.h>#include <string.h>class toon{public:    char name[100];    int str;    int health;    int dex;    int intel;    int charisma;    int wisdom;};char setname();int setstr();int sethealth();int setdex();int setintel();int setchar();int setwis();int rolldice(int);int x=1;int total=0;int roll(int);char name[100];using namespace std;/* *  */int main(int argc, char** argv) {    toon character;    srand((unsigned)time(NULL));    setname();    strcpy(character.name,name);    setstr();    character.str=total;    total=0;    setdex();    character.dex=total;    total=0;    setintel();    character.intel=total;    total=0;    sethealth();    character.health=total;    total=0;    setwis();    character.wisdom=total;    total=0;    setchar();    character.charisma=total;    total=0;    cout<<"\nCharacter attributes:\n";    cout<<"Name: "<<character.name<<"\n";    cout<<"Health: "<<character.health<<"/120"<<"\n";    cout<<"Strength: "<<character.str<<"/30"<<"\n";    cout<<"Dexterity: "<<character.dex<<"/30"<<"\n";    cout<<"Intelligence: "<<character.intel<<"/30"<<"\n";    cout<<"Wisdom: "<<character.wisdom<<"/30"<<"\n";    cout<<"Charisma: "<<character.charisma<<"/30"<<"\n";  return (EXIT_SUCCESS);}char setname(){   cout<<"Lets choose a name! Enter your choice:";    cin.getline(name,100);    cout<<"\nGreat!!! Nice to meet you, "<<name<<", Press <enter> to Continue!"<<endl;    fflush;    cin.get();    }int setstr(){    x=0;    roll(5);    cout<<"Strength is: "<<total<<"\n";}int setdex(){    x=0;    roll(5);    cout<<"Dexterity is: "<<total<<"\n";}int setintel(){    x=0;    roll(5);    cout<<"Intelligence is: "<<total<<"\n";}int sethealth(){    x=0;    roll(20);    cout<<"Health is: "<<total<<"\n";}int setwis(){    x=0;    roll(5);    cout<<"Wisdom is: "<<total<<"\n";}int setchar(){    x=0;    roll(5);    cout<<"Charisma is: "<<total<<"\n";}int roll(int z){  do    {rolldice(z);x=++x;    }    while(x<=z);}int rolldice(int g){ int r; r=rand()%6; total=(total+r+1); cout<<"\n"<<total<<"\n";}    
  You can just put the function calls inside main() in a loop, or move them to a separate function like you noted.int main(int argc, char** argv) {toon character;srand((unsigned)time(NULL));string input;do {    setname();    strcpy(character.name,name);    setstr();    character.str=total;    total=0;    setdex();    character.dex=total;    total=0;    setintel();    character.intel=total;    total=0;    sethealth();    character.health=total;    total=0;    setwis();    character.wisdom=total;    total=0;    setchar();   character.charisma=total;    total=0;    cout<<"\nCharacter attributes:\n";    cout<<"Name: "<<character.name<<"\n";    cout<<"Health: "<<character.health<<"/120"<<"\n";    cout<<"Strength: "<<character.str<<"/30"<<"\n";    cout<<"Dexterity: "<<character.dex<<"/30"<<"\n";    cout<<"Intelligence: "<<character.intel<<"/30"<<"\n";    cout<<"Wisdom: "<<character.wisdom<<"/30"<<"\n";    cout<<"Charisma: "<<character.charisma<<"/30"<<"\n";    cout << "Are you happy with your character (y/n): ";}while(getline(cin, input) && input != "y");return (EXIT_SUCCESS);}Moving them to a separate function and then calling that in a loop would be the cleanest option.Other miscellaneous advice would be to remove the global variables and use the return values of the functions to pass the data around. In particular, note how requiring the user set "x" and "total" to zero could be a source of bugs, if it is omitted.Use std::string instances instead of character arrays, character arrays will cause you lots of headaches because they are not first class types and tend to act in unintuitive ways.;  Thanks so much for the reply and advice.  I understand globals should be minimized, I guess I haven't grasped the return value concept yet though.  I understand functions return values, but in an instance like this, where I call roll, which has the do/while to call rolldice..can you give me an example of how to use the return from the function?  rolldice will return the value to roll, which will have to return that value to getstr, or gethealth or w/e.  so I just put a "return(total)" in rolldice, which hands total to roll, but how do I get it from roll to whichever function calls it?  Do I just add a variable, 'int xyz' and then set xyz=total, return(xyz)??  Sorry, a little lost with the concept :/   ;  Ok well, working on my own, this is what I have so far (although it's not working).I made my function a non-member friend of the class.  I call the function, it's compiles fine, however it's returning 0.  For ease of reading, the only changes I made are:class toon //permission to have setstr() see the class{    friend int setstr(toon& character);   }int create()  //function I'm using to create the character---no longer in main{toon character;  //create the member}setstr(character);  //function callint setstr(toon& character)  //actual function{    int stre;    stre=roll(5);    character.str=stre;}any insight as to why this is always 0?   ;  Alright, a few things:Your create function essentially does nothing. It creates a local toon object, which immediately goes out of scope and is destroyed once the function returns. Read up on scope for some more info into why this happens. Basically, if you declare a variable inside a function, the variable is only accessible inside that function.Also, you don't have any return statements in your functions even though they're declared to return int. First of all, why do you declare them to return anything? It doesn't seem like there's any reason; just declare them to return void instead. Second, if you declare a function to return a certain type, you must write a return statement somewhere inside the function definition. For example, an Add function might look like this:int Add(int a, int b) { return a + b; };I think you should read up on scope and member functions. Once you understand how both work, it'll be easier to see what's wrong with the code you've posted and how to fix it.   ;  Nevermind, I see what you're saying about scope.  Works in the terminal but I'm sure as soon as I wanted to call any of that info from elsewhere it'd be gone.. thanks.   ;  This may be a little better.  Still lots of friends though - not sure I like that.  character is made in main now and shouldn't go out of scope.  #include <cstdlib>#include <cstdio>#include <iostream>#include <math.h>#include <string.h>class toon{    friend int setstr(toon& character);    friend int sethealth(toon& character);    friend int setdex(toon& character);    friend int setchar(toon& character);    friend int setwis(toon& character);    friend int setintel(toon& character);    friend char setname(toon& character);    friend int create(toon& character);public:    char name[100];    int str;    int health;    int dex;    int intel;    int charisma;    int wisdom;};char setname(toon& character);int setstr(toon& character);int sethealth(toon& character);int setdex(toon& character);int setintel(toon& character);int setchar(toon& character);int setwis(toon& character);int rolldice(int);int create(toon& character);int roll(int);using namespace std;/* *  */int main(int argc, char** argv) {    srand((unsigned)time(NULL));    string input;    toon character;    do    {    create(character);    cout<<"\nCharacter attributes:\n";    cout<<"Name: "<<character.name<<"\n";    cout<<"Health: "<<character.health<<"/120"<<"\n";    cout<<"Strength: "<<character.str<<"/30"<<"\n";    cout<<"Dexterity: "<<character.dex<<"/30"<<"\n";    cout<<"Intelligence: "<<character.intel<<"/30"<<"\n";    cout<<"Wisdom: "<<character.wisdom<<"/30"<<"\n";    cout<<"Charisma: "<<character.charisma<<"/30"<<"\n";    cout<<"Are you happy with your character?(y/n)";    }    while(getline(cin,input) && input != "y");    system("clear");return (EXIT_SUCCESS);}int create(toon& character){setname(character);    setstr(character);    setdex(character);    setintel(character);    sethealth(character);    setwis(character);    setchar(character);   }char setname(toon& character){    char name[100];    system("clear");    cout<<"Lets choose a name! Enter your choice:";    cin.getline(name,100);    strcpy(character.name,name);}int setstr(toon& character){    int stre;    stre=(roll(5));character.str=stre;}int setdex(toon& character){    int dext;    dext=(roll(5));    character.dex=dext;}int setintel(toon& character){    int inte;    inte=(roll(5));    character.intel=inte;}int sethealth(toon& character){    int heal;    heal=(roll(20));    character.health=heal;}int setwis(toon& character){    int wisd;    wisd=(roll(5));    character.wisdom=wisd;}int setchar(toon& character){    int chari;    chari=(roll(5));    character.charisma=chari;}int roll(int z){    int r;    int tot=0;    for(int i=0;i<z;i++)    {r=rand()%6;tot=(tot+r+1);    }    return tot;};  Why not just turn all of those friend functions into member functions?   ;  I would advise you to drop all use of character arrays and use std::string instances. That way, you won't have to worry about arbitrary upper limits such as the current 99 character name limit (100 minus the NUL character to terminate the string).Your set* functions can be written like so:int setdex(toon& character){    character.dex = roll(5);}Note how I have removed the unnecessary temporary variable, and the superflous parenthesis.Likewise, roll could be written like so:int roll(int z){   int total = 0;   for(int i = 0 ; i < z ; i++)   {  int r = rand() % 6;  total = total + r + 1;   }   return total;}Things to note this time:Improved use of whitespace to amke it easier to visually scan the codeThe variable "r" is initialised with a value. Uninitialised variables are a frequent source of bugs, it is almost always possible to re-write the code to initialise the variable with some reasonable value.The word "total" is written fully. It is generally a bad idea to abbreviate, you save a few keystrokes but you will spend on average 10 times more time reading the code than writing it, so again it helps to make it easy to understand at a glance.The same could be said of "str", "intel" and "dex" in the "toon" class.   ;  They're covering most of the technical stuff, but in the future, use<code></ code> or <source> </ source> tags for your code. It will keep it's pretty formatting that way and makes it a lot easier to read. I think the source tag is the one that does the word highlighting.   