Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

c++ problem i cant iron out

  • 20-12-2005 08:31PM
    #1
    Closed Accounts Posts: 49


    im writting a small program and i keep getting this error:

    error C2111: pointer addition requires integral operand.

    anyone got any ideas as to the problem?

    heres the whole program:



    #include <iostream.h>
    #include <conio.h>
    #include <string>
    #include <vector>

    using namespace std;

    main()
    {
    float qty, i, lastqty(0),proqty(0) ;
    float width,lenght, panelw(0), panell(0),result(0), wholeframe(0), promeasure(0);
    vector<float> list;
    cout<<"Qty: ";
    cin>>qty;
    cout<<"Width: ";
    cin>>width;
    cout<<"Length: ";
    cin>>lenght;

    while (list.size() >= 0){
    if(qty > 0){
    result = width - 4.25;
    panelw=result;
    panell=lenght-4.25;
    proqty=proqty+qty;
    wholeframe=result+lenght;
    promeasure=promeasure+wholeframe;

    list.push_back(qty + " " + width + " X " + lenght + " " + result + " " + panelw + " X " + panell);


    cout<<"Qty: ";
    cin>>qty;
    cout<<"Width: ";
    cin>>width;
    cout<<"Length: ";
    cin>>lenght;

    }
    i=0;
    while (i < list.size()){
    cout<<list<<endl;
    i++;
    }

    }

    }


Comments

  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭daymobrew


    list.push_back(qty + " " + width + " X " + lenght + " " + result + " " + panelw + " X " + panell);
    
    What are you trying to do here? list is of type float but by putting the spaces it looks like you are trying to create a string.
    I tried changing the list type to 'char *' and using sprintf to create a string to push_back but it caused a run time (Access Violation) error for me. I guess that there is a correct way to achieve this.


  • Closed Accounts Posts: 49 boyracer87


    im trying to put
    "(qty + " " + width + " X " + lenght + " " + result + " " + panelw + " X " + panell);" into the vector<float> so i can cout them as a list.

    for example:
    QTY Width lenght result panelw panell
    2 23 X 45 18.75 18.75 X 40

    do you think it would be easyer to use an array?

    by the way, just in case your wondering, the program is for caculating certain measurments of doors.


Advertisement