"Expressions must have (pointer-to-)" I'm stuck. :(

This is a discussion on "Expressions must have (pointer-to-)" I'm stuck. :( within the C++ Programming forums, part of the General Programming Boards category; So I wrote out my code, and yes there is probably a better way I could have done it, but ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    6

    "Expressions must have (pointer-to-)" I'm stuck. :(

    So I wrote out my code, and yes there is probably a better way I could have done it, but I'm not going for awesome. I just want to get it done. I was almost done and one of my variables came out (pointer-to-). I tried to define in as float, int, and double but nothing worked. Now I'm stuck. Any suggestions? Its on line 28, the second while in my "int main()" section. RoomTiles = RoomTiles + RoomTiles(RoomNumb); Thanks in advance!


    Code:
    #include <cmath>
    #include <iomanip>
    #include <iostream>
    using namespace std; 
    
    //Function prototypes
    void GetRoomNumb (float& RoomNumb);  
    void GetRoomTiles (double& RoomTiles); 
    void GetBoxAmt (float& BoxAmt, float& Extra); 
    
    int main()
    {
        //Variable Declarations
        float RoomNumb; 
        double RoomTiles; 
        float BoxAmt; 
        float Remainder; 
    
        GetRoomNumb(RoomNumb); 
        while (RoomNumb > 0) 
        {
            GetRoomTiles(RoomTiles);  
    
            std :: cout << "Room requires " << RoomTiles << " tiles." << endl; 
    
            while (RoomNumb > 0) 
            {
                RoomTiles = RoomTiles + RoomTiles(RoomNumb); 
            }
    
            RoomNumb--; 
        }
    
        GetBoxAmt(BoxAmt, Remainder); 
        std :: cout << "Total tiles required is " << RoomTiles << "." << endl
                    << "Number of boxes needed is " << BoxAmt << "." << endl 
                    << "There will be " << Remainder << " tiles." << endl; 
    
        return 0; 
    }
    
    
    //**********************************************************************************************************
    void GetRoomNumb (float& RoomNumb) 
    {
        std :: cout << "Enter number of rooms: "; 
        std :: cin >> RoomNumb; 
    }
    
    //**********************************************************************************************************
    void GetBoxAmt (int& BoxAmt, int& Remainder)
    {
        double RoomTiles; 
    
        GetRoomTiles(RoomTiles); 
        BoxAmt = RoomTiles / 20; 
        Remainder = BoxAmt % 20; 
    
        if (Remainder = 0)
        {
            BoxAmt = BoxAmt; 
            Remainder = 0; 
        }
        else
        {
            BoxAmt = BoxAmt + 1; 
            Remainder = BoxAmt % 20; 
        }
    }
    
    //**********************************************************************************************************
    void GetRoomTiles (double& RoomTiles) 
    {
        //Variable Declarations
        int WidthFeet; int LengthFeet; 
        int WidthInches; int LengthInches; 
        int TileInches; 
        int TotalWidthInches; int TotalLengthInches; 
        int WidthTiles; int LengthTiles; 
        int Remainder; int Corner; 
        int WidthTile2; int LengthTile2; 
    
        //Get Values
        std :: cout << "Enter size of tile in inches: "; 
        std :: cin >> TileInches; 
        std :: cout << endl; 
        std :: cout << "Enter room width (feet and inches, separated by a space): "; 
        std :: cin >> WidthFeet >> WidthInches; 
        std :: cout <<endl; 
    
        //Calculate Width
        TotalWidthInches = WidthFeet * 12 + WidthInches; 
        WidthTiles = TotalWidthInches / TileInches; 
        Remainder = TotalWidthInches % TileInches; 
    
        if (Remainder = 0)
        {
            WidthTile2 = 0; 
            Corner = Corner + 0; 
        }
        else
        {
            WidthTile2 = WidthTiles; 
            Corner++; 
        }
    
        //Calculate Length
        TotalLengthInches = LengthFeet * 12 + LengthInches; 
        LengthTiles = TotalLengthInches / TileInches; 
        Remainder = TotalLengthInches % TileInches; 
    
        if (Remainder = 0)
        {
            LengthTile2 = 0; 
            Corner = Corner + 0; 
        }
        else
        {
            LengthTile2 = LengthTiles; 
            Corner++; 
        }
    
        //Calculate Total Tiles
        RoomTiles = (WidthTiles * LengthTiles) + (WidthTile2 + LengthTile2) + Corner; 
    }

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Your definition of RoomTiles is as a double, and on line 28 you are trying to use it as a function. You can't do that.

    What are you trying to do on this line?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Sorry, in a rush - but at first glance -

    Void GetRoomNumb doesnt return anything, perhaps this should return the room number (just a guess).

    Roomtiles is a double but you seem to have tried to call it as a function. Think again about what were you trying to do on this line?

    Like I say - sorry but just about to rush out the door so please excuse the rushed typing!

    Best of luck.

    LOL - Just seen Grahams post!

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    6
    Hmmm, now that I'm looking at it again I can't believe I did that. Teach me to try and program before I have coffee, but I'm still suck. Okay so what I need it to do is add the room tiles together for every room entered.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    45
    Perhaps this is what your trying to do, although you would have to fix some of the problems already posted.


    Code:
        while (RoomNumb > 0) 
        {
            temp = GetRoomTiles();  
    
            std :: cout << "Room requires " << temp << " tiles." << endl; 
    
            RoomTiles += temp;
            RoomNumb--; 
        }
    Last edited by Incantrix; 12-06-2011 at 10:36 AM.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    6
    Maybe that's what I'm trying to do. I put it in my program but all the rest of my program fell apart. So I dunno. I'm going to have to go back through it tonight and change all kinds of stuff. This is what I get for slacking for 5 weeks then deciding to do my homework. Its dumb, I use to be able to get programs like this to work in one shot. I think I was just rushing though it tho.

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    6
    So I fixed the original problem (I think) but now I have a new problem. *super sigh* Suggestions? Its just not been a good programming day for me.

    Now it gets up to the "Total tiles required is " Part and then goes back to Enter size of tile in inches. It doesn't count down the room number and stop when room > 0. I tried both RoomNumb--; and RoomNumb = RoomNumb - 1; It gets to line 28 then starts back at line 18...

    Code:
    #include <cmath>
    #include <iomanip>
    #include <iostream>
    using namespace std; 
    
    //Function prototypes
    void GetRoomNumb (int& RoomNumb);  
    void GetRoomTiles (int& RoomTiles); 
    void GetBoxAmt (int& BoxAmt, int& Remainder); 
    
    int main()
    {
        //Variable Declarations
        int RoomNumb, RoomTiles, TileInches; 
        int BoxAmt, Remainder; 
        int RoomTiles2 = 0; 
    
        GetRoomNumb(RoomNumb); 
        while (RoomNumb > 0) 
        { 
            GetRoomTiles(RoomTiles); 
            std :: cout << "Room requires " << RoomTiles << " tiles." << endl;
     
            RoomTiles2 = RoomTiles2 + RoomTiles;
            RoomNumb = RoomNumb - 1;
        }
    
        std :: cout << "Total tiles required is " << RoomTiles2 << "."; 
    
        GetBoxAmt(BoxAmt, Remainder); 
        std :: cout << "Total tiles required is " << RoomTiles << "." << endl
                    << "Number of boxes needed is " << BoxAmt << "." << endl 
                    << "There will be " << Remainder << " extra tiles." << endl; 
    
    
        system("Pause"); 
        return 0; 
    }
    
    
    //**********************************************************************************************************
    void GetRoomNumb (int& RoomNumb) 
    {
        std :: cout << "Enter number of rooms: "; 
        std :: cin >> RoomNumb; 
    }
    //**********************************************************************************************************
    void GetBoxAmt (int& BoxAmt, int& Remainder)
    {
        int RoomTiles; 
    
        GetRoomTiles(RoomTiles); 
        BoxAmt = RoomTiles / 20; 
        Remainder = BoxAmt % 20; 
    
        if (Remainder = 0)
        {
            BoxAmt = BoxAmt; 
            Remainder = 0; 
        }
        else
        {
            BoxAmt = BoxAmt + 1; 
            Remainder = BoxAmt % 20; 
        }
    }
    
    //**********************************************************************************************************
    void GetRoomTiles (int& RoomTiles) 
    {
        //Variable Declarations
        int WidthFeet,  WidthInches, TotalWidthInches, WidthTiles,  WidthTile2;
        int LengthFeet,  LengthInches, TotalLengthInches, LengthTiles, LengthTile2;
        int Remainder, TileInches; 
        int Corner; 
    
        //Get Values
        std :: cout << "Enter size of tile in inches: "; 
        std :: cin >> TileInches;
        std :: cout << endl << "Enter room width (feet and inches, separated by a space): "; 
        std :: cin >> WidthFeet >> WidthInches; 
        std :: cout << endl << "Enter room length (feet and inches, separated by a space): "; 
        std :: cin >> LengthFeet >> LengthInches; 
    
        //Calculate Width
        TotalWidthInches = WidthFeet * 12 + WidthInches; 
        WidthTiles = TotalWidthInches / TileInches; 
        Remainder = TotalWidthInches % TileInches; 
        Corner = 0; 
    
        if (Remainder = 0)
        {
            WidthTile2 = 0; 
            Corner++; 
        }
        else
        {
            WidthTile2 = WidthTiles; 
            Corner = 1; 
        }
    
        //Calculate Length
        TotalLengthInches = LengthFeet * 12 + LengthInches; 
        LengthTiles = TotalLengthInches / TileInches; 
        Remainder = TotalLengthInches % TileInches; 
    
        if (Remainder = 0)
        {
            LengthTile2 = 0; 
            Corner = Corner + 0; 
        }
        else
        {
            LengthTile2 = LengthTiles; 
            Corner = 1; 
        }
    
        //Calculate Total Tiles
        RoomTiles = (WidthTiles * LengthTiles) + (WidthTile2 + LengthTile2) + Corner; 
    }
    Last edited by Shmamy; 12-06-2011 at 10:50 PM.

  8. #8
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Code:
    void GetRoomNumb (int& RoomNumb) { std :: cout << "Enter number of rooms: "; std :: cin >> RoomNumb; }


    This function is declared as a void - so it asks for user input but returns nothing.

    How about declaring it as an integer and returning that value to use for your counter?

    Read through this and you will see what I mean.

    Code:
    
    #include <iostream>
    using namespace std;
    
    int getroomnumber();/* declares a function that returns an integer */
    
    
    int main() {
    
    
        int RoomNumb = 0; /* declares the variable "RoomNumb" as an integer
                                           and assigns it a value of zero*/
    
             RoomNumb = getroomnumber(); /* calls the function and assigns the
                                        returned value to the variable "RoomNumb"*/
    
             cout << "number of rooms is: " << RoomNumb << endl;
            /* This output confirms that our program worked */
    
    
    return 0;
    }
    
    
    /* this is the function */
    int getroomnumber(){
    
         int x=0; /* declares the variable x as an integer */
    
             cout << "input number of rooms: ";
            cin >> x; /* collects a number and assigns it to the variable x */
    
    return x; /* returns the value of x as an integer to the line of code
                                                            that called it. */
    }
    PS - Hope you can read this - I used code /code tags but the formatting seems to have gone bonkers here... Good Luck.
    Last edited by Brian_of_Bozeat; 12-07-2011 at 02:58 AM.

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,738
    Actually Brian, since the parameter is a reference, the function should change the argument you give, which must be an l-value. Using references you don't really need to return things, and it is one of the easiest ways to get more than one piece of output from a function.

  10. #10
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    You are right whiteflags - my Error.
    Sorry shmamy, I was suggesting using pass by Value... My Apologies.
    You were using pass by reference, so - I have included here a stripped out version of that instead... hope it helps.

    Code:
    #include <cmath>
    #include <iomanip>
    #include <iostream>
    using namespace std;
    
    
    //Function prototypes
    void GetRoomNumb(int *r);
    
    
    int main()
    {
        //Variable Declarations
        int RoomNumb;
    
    
        GetRoomNumb(&RoomNumb);
    
    
        while (RoomNumb > 0)
        {
            cout << "Room numb is " << RoomNumb << endl;
    
    
    
    
        return 0;
    }
    }
    
    
    
    
    void GetRoomNumb(int *r){
        cout << "Enter number of rooms: ";
        cin >> *r;
    }
    Last edited by Brian_of_Bozeat; 12-07-2011 at 08:40 AM. Reason: code tags still not working... Grrr

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,756
    This is not by reference. This is by pointer or address.
    By reference is:
    Code:
    void GetRoomNumb(int & r)
    {
        cout << "Enter number of rooms: ";
        cin >> r;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Thank you for your help Elysia:

    I stand corrected.
    Last edited by Brian_of_Bozeat; 12-07-2011 at 09:49 AM.

  13. #13
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Dear Shmamy,

    Many apologies for my earlier erroneous suggestions to the problem with your program. By way of an apology for the confusion I have spent some time debugging your program.

    Now it gets up to the "Total tiles required is " Part and then goes back to Enter size of tile in inches."
    The behaviour you describe is happening because when your program calls "GetBoxAmt" that function then calls "GetRoomTiles". if you // this call from within "GetBoxAmt" then the program terminates as expected - although I'm not sure what that will have done to your maths...

    I do hope this helps. I think I learned more than you did!
    Best of luck, Brian.

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    6
    Haha its okay. Everyone has to be wrong at some point or another! That's how we learn. I ended up rewriting it quite a bit and now for the most part it does what it is suppose to. To the point where I can at least get credit for it. Thanks everyone for your help! If anyone is curious what I ended up doing, I'm putting it below this.

    Code:
    
    #include <cmath>
    #include <iomanip>
    #include <iostream>
    using namespace std; 
    
    //Function prototypes
    void GetRoomNumb (int& RoomNumb);  
    void GetRoomTiles (int& RoomTiles); 
    void GetBoxAmt (int& BoxAmt, int& Remainder); 
    
    int main()
    {
        //Variable Declarations
        int RoomNumb, RoomTiles, TileInches; 
        int BoxAmt, Remainder; 
        int RoomTiles2 = 0; 
    
        GetRoomNumb(RoomNumb); 
        while (RoomNumb > 0) 
        { 
            GetRoomTiles(RoomTiles); 
            std :: cout << "Room requires " << RoomTiles << " tiles." << endl;
     
            RoomTiles2 = RoomTiles2 + RoomTiles;
            RoomNumb = RoomNumb - 1;
        }
    
        std :: cout << "Total tiles required is " << RoomTiles2 << "." <<endl; 
     
        BoxAmt = RoomTiles2 / 20; 
        Remainder = BoxAmt % 20; 
    
        if (Remainder != 0)
        {
            BoxAmt = BoxAmt + 1;  
        }
    
        std :: cout << "Number of boxes needed is " << BoxAmt << "." << endl 
                    << "There will be " << Remainder << " extra tiles." << endl; 
    
    
        system("Pause"); 
        return 0; 
    }
    
    
    //**********************************************************************************************************
    void GetRoomNumb (int& RoomNumb) 
    {
        std :: cout << "Enter number of rooms: "; 
        std :: cin >> RoomNumb; 
    }
    
    //**********************************************************************************************************
    void GetRoomTiles (int& RoomTiles) 
    {
        //Variable Declarations
        int WidthFeet,  WidthInches, TotalWidthInches, WidthTiles,  WidthTile2;
        int LengthFeet,  LengthInches, TotalLengthInches, LengthTiles, LengthTile2;
        int Remainder, TileInches; 
        int Corner; 
    
        //Get Values
        std :: cout << "Enter size of tile in inches: "; 
        std :: cin >> TileInches;
        std :: cout << "Enter room width (feet and inches, separated by a space): "; 
        std :: cin >> WidthFeet >> WidthInches; 
        std :: cout << "Enter room length (feet and inches, separated by a space): "; 
        std :: cin >> LengthFeet >> LengthInches; 
    
        //Calculate Width
        TotalWidthInches = WidthFeet * 12 + WidthInches; 
        WidthTiles = TotalWidthInches / TileInches; 
        Remainder = TotalWidthInches % TileInches; 
        Corner = 0; 
    
        if (Remainder = 0)
        {
            WidthTile2 = 0; 
            Corner++; 
        }
        else
        {
            WidthTile2 = WidthTiles; 
            Corner = 1; 
        }
    
        //Calculate Length
        TotalLengthInches = LengthFeet * 12 + LengthInches; 
        LengthTiles = TotalLengthInches / TileInches; 
        Remainder = TotalLengthInches % TileInches; 
    
        if (Remainder = 0)
        {
            LengthTile2 = 0; 
            Corner = Corner + 0; 
        }
        else
        {
            LengthTile2 = LengthTiles; 
            Corner = 1; 
        }
    
        //Calculate Total Tiles
        RoomTiles = (WidthTiles * LengthTiles) + (WidthTile2 + LengthTile2) + Corner; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am stuck with "2/5", Need help or advice
    By dapping in forum C Programming
    Replies: 8
    Last Post: 09-24-2011, 03:34 PM
  2. Replies: 14
    Last Post: 11-08-2010, 12:47 AM
  3. "*x + *x++" Address/Pointer "?"
    By Marth_01 in forum C Programming
    Replies: 10
    Last Post: 11-05-2008, 03:33 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21