Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,570 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,100 people online right now. Registration is fast and FREE... Join Now!




A small problem

 
Reply to this topicStart new topic

A small problem, trying to fix code with an if statement

gryphin
post 25 Dec, 2005 - 09:45 PM
Post #1


New D.I.C Head

Group Icon
Joined: 29 Oct, 2005
Posts: 43



Dream Kudos: 25
My Contributions


I am posting the code for reference. I am trying to set up a generator for HP to create a character for a rpg I play. I have documented the code pretty well, but if there are any questions let me know. I am just trying to figure out what I did wrong with the if statement. I have not been programming long, so I am somewhat prone to the little mistakes. Please help!!!


Attached File(s)
Attached File  HPGenerator.cpp ( 2.44k ) Number of downloads: 13
User is offlineProfile CardPM

Go to the top of the page


fyrestorm
post 26 Dec, 2005 - 12:03 AM
Post #2


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 1 times

Dream Kudos: 228
My Contributions


i just took a quick look at your code, and this is what i noticed:

you never call your dice function
and within your dice function lvl is not defined (and it's not passed to the function)...
and your dice function is returning a variable that is never assigned a value...

just a few quick things i saw...nothing too difficult to fix...
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 26 Dec, 2005 - 05:05 AM
Post #3


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,158



Thanked 32 times

Dream Kudos: 25
My Contributions


In addition to the points that fyrestorm has made, the if statement to which you are referring is not structured properly. Only command statements require a semi colon at the end, comparative statements do not.

This
CODE

if( int totalHp <=1 );
    {
 totalHp=1;
 cout << totalHp;
    }
    else
    {    
 cout << totalHp;
    }

should be
CODE

if(totalHp <=1 )
    {
 totalHp=1;
 cout << totalHp;
    }
    else
    {    
 cout << totalHp;
    }
User is offlineProfile CardPM

Go to the top of the page

Mrafcho001
post 26 Dec, 2005 - 10:54 AM
Post #4


D.I.C Addict

Group Icon
Joined: 1 Nov, 2005
Posts: 753



Thanked 5 times

Dream Kudos: 120
My Contributions


QUOTE(fyrestorm @ 26 Dec, 2005 - 02:00 AM)
i just took a quick look at your code, and this is what i noticed:

you never call your dice function
and within your dice function lvl is not defined (and it's not passed to the function)...
and your dice function is returning a variable that is never assigned a value...

just a few quick things i saw...nothing too difficult to fix...

Actualy lvl is defined as a global variable.

However you are using totalDice in your main scope without initializing it. Thats gonna cause some problems.

Also at the end instead of having:

CODE

char input;
cin >> input;
//You can do this:
system("PAUSE");


The rest of the problems have been pointed out by Amadeus and fyrestorm

This post has been edited by Mrafcho001: 26 Dec, 2005 - 10:54 AM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 03:15AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month