Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 13th, 2005, 3:49 PM   #1
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
Character creation tutorial

I am a begginer, and just thought that i could put some of the tutorials you would find on forums, into a working code that could actually be useful to some of you later on in your programming career. This tutorial is for begginers, please criticize me, comment, and anything else you feel.. just remember this is my first program other than hello world pretty much so i am really proud of myself, also proud of how long it is, even though that might not be important

/* Character creation tutorial for begginers. Any questions, concerns or comments
can be e-mailed to iced_out_jay@hotmail.com. Include credits if you use this tutorial
on your website. Created by: Jayme Schroeder.*/

#include <stdio.h>
#include <windows.h>
#include <string>
#include <iostream.h>

using namespace std;

int main()
{
    int Points = 20;             // These are the max points you can spend on your skills (agility, strength, and intelligents.
    int Str = -1;                // This is your characters strength skill level.
    int Int = 0;                 // This is your characters intelligents skill level.
    int Agi = 0;                 // This is your characters agility skill level.
    char Name[500];              // This is your characters name.
    
    cout << "this is a test created by Jay to see if he has even" << endl << "learned anything since he started c++ programming.. ok so here it goes.\n\n";
    cout << "Press enter to continue to the character creation proccess.\n\n"; // This is the initialization of the program. It tells you whats going to happen.
    cin.get();
    system("cls");
    cout << "Name your character: "; // Character naming process.
    cin >> Name;
    cout << "Ok, so now we have your characters name.\n\n";
    cout << "Now we will continue to your character's stats. You only have 20 points, so use them wisely.\n\n"; // Point system, add skill points to your abilities with these points.
    system("cls");


/* This is the Strength skill code.*/

    strength: // This is the strength loop, if you enter a number larger than 20 or less than 1, you will be taken back to this step.
          cout << "Enter your strength: "; 
          cin >> Str;
    
          if ( Str < 1 ) { // If the input is less than 1, the string below is executed and you will be asked to input a new integer.
               cout << "You Must spend at least one point!\n\n"; 
               }
    
          if ( Str > Points ){ // If the input is greater than the existing points, the string below will be executed and you will be asked to input a new integer.
          cout << "You don't have enough points!\n\n";
}
          if ( Str >= 20 ) goto strength; // If you enter a larger number of skill points than are available, you will be asked to input a new number.
          if ( Str <= 0 ) goto strength; // If you enter a less than number of skill points than are available, you will be asked to input a new number.
    cout << "Strength leveled up to " << Str << "!" << endl; // Lets you know that your selected integer was successfully added.
    Points = Points - Str; // Adds the selected points on to strength and reduces that same amount from your remaining skill points.
    cout << "You have " << Points << " skill points remaining.\n\n";


/* This is the Agility skill code.*/

    agility: // This is the agility loop, if you enter a number larger than 20 or less than 1, you will be taken back to this step.
          cout << "Enter your agility: ";
          cin >> Agi;
    
          if ( Agi < 1 ) { // If the input is less than 1, the string below is executed and you will be asked to input a new integer.
               cout << "You Must spend at least one point!\n\n"; 
               }
    
          if ( Agi > Points ){ // If the input is greater than the existing points, the string below will be executed and you will be asked to input a new integer.
          cout << "You don't have enough points!\n\n";
}
          if ( Agi >= Points ) goto agility; // If you enter a larger number of skill points than are available, you will be asked to input a new number.
          if ( Agi <= 0 ) goto agility; // If you enter a less than number of skill points than are available, you will be asked to input a new number.
    cout << "Agility leveled up to " << Agi << "!" << endl; // Lets you know that your selected integer was successfully added.
    Points = Points - Agi; // Adds the selected points on to agility and reduces that same amount from your remaining skill points.
    cout << "You have " << Points << " skill points remaining.\n\n";


/* This is the Intelligents skill code.*/

    intel: // This is the intelligents loop, if you enter a number larger than 20 or less than 1, you will be taken back to this step.
          cout << "Enter your intelligents: ";
          cin >> Int;
    
          if ( Int < 1 ) { // If the input is less than 1, the string below is executed and you will be asked to input a new integer.
               cout << "You Must spend at least one point!\n\n"; 
               }
    
          if ( Int > Points ){ // If the input is greater than the existing points, the string below will be executed and you will be asked to input a new integer.
          cout << "You don't have enough points!\n\n";
}
          if ( Int > Points ) goto intel; // If you enter a larger number of skill points than are available, you will be asked to input a new number.
          if ( Int <= 0 ) goto intel; // If you enter a less than number of skill points than are available, you will be asked to input a new number.
    cout << "Intelligents leveled up to " << Int << "!" << endl; // Lets you know that your selected integer was successfully added.
    Points = Points - Int; // Adds the selected points on to intelligents and reduces that same amount from your remaining skill points.
    cout << "You have " << Points << " skill points remaining.\n\n";


/* This is the last segment of the code, it prints to the screen the name of your new character and your characters stats. */

   system ("cls");
   cout << "Congratulations, you have created your character successfully!\n\nHere is your character:\n\nCharacter name: " << Name << "\nAgility: " << Agi << "\nStrength: " << Str << "\nIntelligents: " << Int;

cin.get();
}
jayme is offline   Reply With Quote
Old Nov 13th, 2005, 4:31 PM   #2
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
Nice piece of code but don't you think that char Name[500]; is a little unnecessary?
ivan is offline   Reply With Quote
Old Nov 13th, 2005, 4:48 PM   #3
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
lol, ya.. i was just playin around with that and didnt really bother to change it to anything else, in reality it would probably be set to 15 or something. I'll fix it now since it is a tutorial.

EDIT: Can't edit my first post, for anyone who might actually use this tutorial, it should look more like this.

    char Name[15];      (this is the max amount of characters(letters) a character name is allowed to be)
jayme is offline   Reply With Quote
Old Nov 13th, 2005, 5:06 PM   #4
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
I think is better use 'while' or 'do while' for the loops, instead of the goto statement...
-=PARADOX=- is offline   Reply With Quote
Old Nov 13th, 2005, 5:10 PM   #5
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
ya, i was tryin to use while first.. but it didnt want to work and i couldnt figure out what i was doin wrong.
jayme is offline   Reply With Quote
Old Nov 13th, 2005, 5:14 PM   #6
Justin Case
Newbie
 
Justin Case's Avatar
 
Join Date: Aug 2005
Location: In the void between my two monitors...
Posts: 15
Rep Power: 0 Justin Case is on a distinguished road
Send a message via AIM to Justin Case
I agree with Paradox... the 'goto' statement isn't the best thing to use...

I'm new to C/C++ (Well I'm learning C) too... maybe I'll try this... But I'll use 'while' not 'goto'...
__________________
... after all, we're all alike.
Justin Case is offline   Reply With Quote
Old Nov 13th, 2005, 5:24 PM   #7
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
if you find out how while works on this app, post here please.
jayme is offline   Reply With Quote
Old Nov 13th, 2005, 5:26 PM   #8
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Just an example...

do {
     cout << "Enter your strength: ";
     cin >> Str;

     if ( Str < 1 ) // If the input is less than 1, the string below is executed and you will be asked to input a new integer.
     cout << "You Must spend at least one point!\n\n";

     if ( Str > Points ) // If the input is greater than the existing points, the string below will be executed and you will be asked to input a new integer.
     cout << "You don't have enough points!\n\n";
} while ( Str >= 20 && Str <= 0 );

cout << "Strength leveled up to " << Str << "!" << endl; // Lets you know that your selected integer was successfully added.
Points = Points - Str; // Adds the selected points on to strength and reduces that same amount from your remaining skill points.
cout << "You have " << Points << " skill points remaining.\n\n";
-=PARADOX=- is offline   Reply With Quote
Old Nov 13th, 2005, 5:42 PM   #9
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
I get this compile error 3 times (once for str, agi, and int,) when i tried using your example. "expected primary-expression before '<=' token"

EDIT: haha nevermind, wow im stupid, i never put the second variable for <=, god damn im stupid
jayme is offline   Reply With Quote
Old Nov 13th, 2005, 6:44 PM   #10
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Ups... my mistake...

in "while ( Str >=20 && Str<=0 )" it sould be "while ( Str >=20 || Str<=0 )".
-=PARADOX=- is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC