Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ error i cant get rid of!!

  • 20-12-2005 7:09pm
    #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: 15,626 ✭✭✭✭vectra


    I have an idea..
    Post it in the right forum and some people that know about coding etc. might be able to help out :D


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    don't know much about c++ but i stuck this code into dev-C++ and it's showing that the error you are getting is located on this line
    list.push_back(qty + " " + width + " X " + lenght + " " + result + " " + panelw + " X " + panell);
    


  • Registered Users, Registered Users 2 Posts: 6,324 ✭✭✭tallus


    how is that relevant to the models board?
    Yeah what vectra said


  • Closed Accounts Posts: 49 boyracer87


    sorry guys. i was in the programming forum before and forgot that i changed to this one:confused: :rolleyes:


  • Registered Users, Registered Users 2 Posts: 6,324 ✭✭✭tallus


    It happens heh


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,626 ✭✭✭✭vectra


    boyracer87 wrote:
    sorry guys. i was in the programming forum before and forgot that i changed to this one:confused: :rolleyes:

    No wonder you cant sort it... you cant even remember what forum you are on :D:D:D


    Only messing m8.
    Nothing personal and no offence meant.. Just having a laugh ;)


  • Closed Accounts Posts: 150 ✭✭Vuk


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

    error C2111: pointer addition requires integral operand.

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

    As your program stands, all thats going into the vector is the addition of all your variables, ie qty is being added to width and in turn being added to length and so forth... and you end up with one result!
    Whats happening with the error is that you're trying to use additon on non float values and also 'insert' them into a vector that holds floating point numbers. Some extra detail on what you're trying to achieve might help!
    At a guess, are you trying to hold a record of inputs & results with seperators?


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    lenght <--- is that a typo?


  • Registered Users, Registered Users 2 Posts: 2,695 ✭✭✭Darwin


    Briefly, you've several problems. Your vector is set up to store float's, but you're trying to store strings in it. There is no string concatenation operator (+) in C++ (such as there is in Java). To concatenate say a string and a float to produce a string, you need to use a stringstream. For example:

    #include <sstream>
    ...
    ostringstream strStream; // Construct an output string stream
    float y = 3.14f;
    string s = "PI: ";
    strStream << s << y;
    cout << strStream.str(); // outputs "PI: 3.14"
    strStream.str(""); // Empties the stringstream

    You also have an infinite outer while loop - a vector's size can never be negative. Additionally, you are constantly appending to the vector so it's size will never reduce...the code below compiles and runs, though you might want to rethink what you are trying to do...
    #include <iostream>
    //#include <conio.h>
    #include <string>
    #include <vector>
    #include <sstream>
    
    using namespace std;
    
    main()
    {
    float qty, lastqty(0),proqty(0) ;
    float width,lenght, panelw(0), panell(0),result(0), wholeframe(0), promeasure(0);
    vector<string> list;
    ostringstream strstream;
    
    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;
    
    strstream << qty << " " << width << " X " << lenght << " " << result << " " << panelw << " X " << panell;
    list.push_back(strstream.str());
    strstream.str("");
    
    cout<<"Qty: ";
    cin>>qty;
    cout<<"Width: ";
    cin>>width;
    cout<<"Length: ";
    cin>>lenght;
    
    }
    int i=0;
    while (i < list.size()){
    cout<<list[i]<<endl;
    i++;
    }
    
    }
    
    }
    
    


  • Closed Accounts Posts: 49 boyracer87


    Thanks man. that is exactly what i was trying to do.

    cheers,
    Ray


  • Advertisement
Advertisement