Thread: Help plz

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    75

    Help plz

    Hello Iwas just messing around with some stuff I was learning and I have some small code to show I cant actually get this working it used to have lots of errors but I got it down to only one(and I'm pretty proud of that) anyway it's kinda obvious what it does (or what I am making it try to do) if u want to know what I am doing here is trying to manipulate the value of an int using a pointer and then after I get this one done I will be trying the same with a reference to the value or something anyway I'm still learning so plz feel free to help



    cheers


    stealth



    #include <iostream.h>
    #include <stdlib.h>


    int main()
    {
    int hit_points = 100;
    int *pointer_to_hitpoints = & hit_points;
    int damage = 10;
    int new_hit_points;
    new_hit_points = (pointer_to_hitpoints - damage);

    system("pause");
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    75

    oh sorry

    and heres the error message I get


    assignment to `int' from `int *' lacks a cast


    plz help somebody I've got this error with a few things so fixing this would be a great help

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    75
    just checking to se eif the thingy at the bottom of my post has changed
    If I knew what You know I wouldnt be here.............. Stealth

    Ecliptic Entertainment
    http://www.ecliptic-entertainment.com/

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    43
    What are you trying to achieve?
    Maybe this *pointer_to_hitpoints:

    int main()
    {
    int hit_points = 100;
    int *pointer_to_hitpoints = & hit_points;
    int damage = 10;
    int new_hit_points;
    new_hit_points = (*pointer_to_hitpoints - damage);

    system("pause");
    return 0;
    }

    "pointer_to_hitpoints - damage" means a pointer to int, which is "damage" ints offseted from "pointer_to_hitpoints", e.g.:

    int pointers[100];
    int* intPointer = &pointers[90]; //same as = pointers + 90

    int* newintPointer = intPointer - 10;//newintPointer points
    //to the 80th element

  5. #5
    Registered User Tazar's Avatar
    Join Date
    Aug 2001
    Posts
    13
    I don't know if this is what you wanted but it works ^_^

    #include <iostream.h>
    #include <stdlib.h>


    int main()
    {
    int hit_points = 100;
    int *pointer_to_hitpoints =(int*)hit_points; //I just made it use the pointer with a type cast.
    int damage = 10;
    int new_hit_points;
    new_hit_points =(int)pointer_to_hitpoints - damage;
    cout<<"Hitpoints: "<<new_hit_points<<endl;
    //system("pause");
    return 0;
    }

    the only thing I found wrong was it was not being type-casted and so was giving a error about making a int into a int *

    Hope I helped a bit.
    Tazar The Demon
    -------------------------------------
    Please check my site out at: http://www.lrs.8m.com thanks =)
    -------------------------------------
    Note:
    I will help newbies and any other person that I can just ask I'll try to help you out =)

    My MSN Messager name is: [email protected] see if I'm online maybe we can talk. =)

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    75
    ok thanks for all the help guys I'll go check this out now to see if it is what I was after actually heres what I was trying to do I dunno if its possible though:



    have a value of 100;
    have a value of 10;
    have a pointer to the value of 100;
    take away the 10 from the 100 using the pointer to the 100;



    I know this is not the best way for doing something this simple but I was just experimenting


    cheers


    stealth
    If I knew what You know I wouldnt be here.............. Stealth

    Ecliptic Entertainment
    http://www.ecliptic-entertainment.com/

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    have a value of 100;
    have a value of 10;
    have a pointer to the value of 100;
    take away the 10 from the 100 using the pointer to the 100
    Code:
    int main()
    {
        int v0 = 100; // have a value of 100
        int v1 = 10; // have a value of 10
        int* pv0 = &v0; // have a pointer to the value of 100
    
        *pv0 -= v1; // take away 10 from the 100 using the pointer to the 100
    
        return 0;
    }
    - lmov

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM