cbrawl's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Members
Active Posts:
30 (0.02 per day)
Joined:
19-December 10
Profile Views:
1,338
Last Active:
User is offline Jun 27 2014 06:09 PM
Currently:
Offline

Previous Fields

Country:
CA
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   cbrawl has not set their status

Posts I've Made

  1. In Topic: Using multiple Functions in C

    Posted 23 Jun 2014

    View Postjimblumberg, on 23 June 2014 - 03:38 PM, said:

    View Postcbrawl, on 23 June 2014 - 02:36 PM, said:

    - define all your functions (insert, dollars, remove, display

    main()
    {
    }
    
    
    [/qoute]
    The main() function should be defined to return an int, and you should return an int from this function. Also use code tags when posting code!

    :code:/>

    [qoute]
    int addUp(int myInt1 int myInt2);
    void printNum(int total);
    
    ...
    
    addUp(int myInt1, int myInt2)
    {
        return myInt1+myInt2;
    }
    
    printNum(total)
    {
       -your printf statement using the variable total
    }
    
    
    


    These function prototypes and function implementations don't match, they must. And remember the current C standard no longer allows default function return values you must implicitly state these return values.

    Jim


    correct! Sorry. I wrote that on the fly without an IDE. Other than that I hope he was able to understand the concept of functions.
  2. In Topic: Using multiple Functions in C

    Posted 23 Jun 2014

    View Postjimblumberg, on 23 June 2014 - 03:38 PM, said:

    View Postcbrawl, on 23 June 2014 - 02:36 PM, said:

    - define all your functions (insert, dollars, remove, display

    main()
    {
    }
    
    
    [/qoute]
    The main() function should be defined to return an int, and you should return an int from this function. Also use code tags when posting code!

    :code:/>

    [qoute]
    int addUp(int myInt1 int myInt2);
    void printNum(int total);
    
    ...
    
    addUp(int myInt1, int myInt2)
    {
        return myInt1+myInt2;
    }
    
    printNum(total)
    {
       -your printf statement using the variable total
    }
    
    
    


    These function prototypes and function implementations don't match, they must. And remember the current C standard no longer allows default function return values you must implicitly state these return values.

    Jim


    correct! Sorry. I wrote that on the fly without an IDE. Other than that I hope he was able to understand the concept of functions.
  3. In Topic: Using multiple Functions in C

    Posted 23 Jun 2014

    Hey man let me try to give you some pointers and sorry if I'm confused by the structor of your code. Okay so I'm not sure how much you know about functions and scope so I'll start with that. If inside a function you use a variable "total", and then use "total" in another function, these are two difference variables that just happen to have the same name. This is what happens... When you start a code block {} anything between the curly braces will only have access to variables inside that block (and others like global variables or pre-processor variables) so this will be the setup of your code...

    - define all your functions (insert, dollars, remove, display
    main()
    {
    }
    
    insert()
    {
    }
    
    

    dollars() and so on...

    You use main, which is also a function in and of itself, to retrieve information from other functions. So if I wanted to add variable myNum1 to myNum2 and store it in myNum3, and print it out, doing so in two function addUp() and printNum() it would look like this...
    int addUp(int myInt1 int myInt2);
    void printNum(int total);
    
    int main()
    {
       -get int from user
       -store int in myNum1
       -get int from user
       -store in in myNum2
       -put muNum1 and myNum2 into the addUp function like so...
       int total = addUp(myNum1, myNum2);
       - print the total in the printNum function like so...
       printNum(total);
       return 0;
    )
    
    addUp(int myInt1, int myInt2)
    {
        return myInt1+myInt2;
    }
    
    printNum(total)
    {
       -your printf statement using the variable total
    }
    
    

    note that "total" in the main function and "total" in the printNum function are two different variables holding the same value. I could have changed the printNum's total to myTotal and it would still accept "total" from the main function.

    Hope this helps and I hope i didn't explain a bunch of stuff you already knew.
  4. In Topic: Where do I include Pointers in a Card Game?

    Posted 21 Jun 2014

    This is a pretty big project if your just starting out in C++. Like the previous person mentioned you will need to organize your objects and use virtual funtions. So if you had a mage, a warrior, and a rogue class of cards you might set up your files like so...

    hero.cpp - this will hold everything that all heros have in common plus the virtual funtion that could account for something like hitting an opponent
    mage.cpp - mage related properties and answers for the virtual functions
    warrior.cpp - warrior ""
    rogue.cpp - rogue ""

    For example if a hero was to hit an enemy they might have different types of attacks. A mage could have a fireball and a rogue could have a backstab. Both of these are still attacks however and will use an attack function from the hero class. When the complier sees that the hero class has a virtual function it will look into the child classes to find a match for that attack function.

    As for pointers, they are just references that point to the address of a given variable. So theoretically, you could point to any variable and use the pointer to reference that variable. Your teacher could possibly, in addition, want you to point to the object when you use it in your main.cpp. Hope this helps and I hope this is a final project in your course because it will be pretty time consuming.
  5. In Topic: simulator for dice rolling

    Posted 4 Jun 2014

    The problems here are you started coding before you even thought about how to solve the problem. Before you start the problem make some points on parts of the program and the linearity of them. Secondly, you don't understand functions properly and you don't understand how variables work because of code like this...

    sum = num1 + num2

    What you think it does - Adds the sum of num1 and num2 and will hold that value to add to the next set of num1 and num2
    What it actually does - Adds the sum of num1 and num2 and will just add the new num1 and num2 together and lose it's current value before doing so

    What you want to be coding
    int totalSum = 0; // initialized to zero
    sum = num1 + num2;
    totalSum += sum; // this will add the sum all of the collected sums so far to the current sum

My Information

Member Title:
New D.I.C Head
Age:
28 years old
Birthday:
June 6, 1986
Gender:
Programming Languages:
C++

Contact Information

E-mail:
Private

Friends

Comments

cbrawl has no profile comments yet. Why not say hello?