PCPartPicker

  • Log In
  • Register

Been quite a while since I've written code. Is this sound?

Forum Search

Guidelines

  • Be respectful to others
  • No spam
  • No NSFW content
  • No piracy or key resellers
  • No link shorteners
  • Offensive content will be removed

Topic

tragiktimes101 4 months ago

So, I need to figure out the weight of a cardboard box by it's external dimensions. I believe I have figured out a way that seems to fit within a margin of error that I'm happy with. So, I tried to put it to code but don't currently have a compiler installed. Is this sound? Am I missing anything? I probably screwed the syntax all up.

#include <iostream>


int main()

    {

    double length, width, height, totalExternalArea, startingArea,    //Declare variables
    cardboardWeight, itemWeight, packageWeight,                        //
    coeficientOfSize = 1.166544,                                                   //
    cardboardWeightPerInch = .00100629;                                   //

    cout << "Enter the length, width, and height" << endl;           //request dimensions      
    cin >> length, width, height;                                                   //user inputs dimensions   
    cout << "Enter the item weight" << endl;                               //request item weight      
    cin >> itemWeight;                                                                //user inputs item weight

    ((length*height * 2) + (legth*width * 2) + (height*width * 2)) = totalExternalArea;    //calculate total area of made box

    (totalExternalArea * coeficientOfSize) = startingArea;  //calculate total area of cardboard

    (startingArea * cardboardWeightPerInch) = cardboardWeight;  //calculate cardboard weight

    (itemWeight + cardboardWeight) = packageWeight; //calculate package weight

    cout << packageWeight;  //display package weight

    return 0;

    }

Comments Sorted by:

ssjg5rlly 3 points 4 months ago

I don't know. I can't hear it. ;)

What kind is it? Javascript? Lua?

[comment deleted]
[comment deleted]
gorkti200 2 Builds 3 points 4 months ago

(legth*width * 2)

Misspelling of length here.

I don't get the syntax very well, I don't do C++, but it seems like after you get user inputs, you are just jumping into equations and assigning the values to variables. Maybe that is normal C++ but to me it seems like you should require a function?

tragiktimes101 submitter 1 Build 1 point 4 months ago

I was assuming the values to two of the variables that I've previously attained average range values for. They are kind of like my coefficients. But, yeah, my syntax sucks, lol.

[comment deleted]
tragiktimes101 submitter 1 Build 2 points 4 months ago

And this does seem like an Intro to C++ or an Intro to Programming level problem where concepts of methods and classes really haven't been introduced yet.

It's actually for here.

Siwini 2 points 4 months ago

Maybe it's within the margin of error, doesn't a cardboard box have flaps? If so then the top and bottom weigh more because of more surface area? Nitpicking? Also check spelling.

tragiktimes101 submitter 1 Build 1 point 4 months ago

Yes. I went about trying to account for this two ways settling on the last. First I found a coefficient that matched the difference between the area of a box's constituent cardboard area and the external area of a made box. But using this I was able to roughly (within about a .1 lb. margin of error) calculate the total area based off the external dimensions. From there I am able to multiply that by the weight of cardboard per in2. This method worked by the margin of error was above my liking.

So, instead I just used a range of boxes (used 10) to find the average weight per square inch based off just the external area. By forming an average and then slightly modifying it I think I've gotten all of the possibilities within a margin of error around .03 lbs. Since our scales are only sensitive to around .05 lbs. this was about as good as I could get it I think.

Siwini 2 points 4 months ago

Agreed, if the cardboard's densities and the box sizes are all different, some sort of "rule of thumb" coefficient is the trick.

[comment deleted]
[comment deleted]
tragiktimes101 submitter 1 Build 1 point 4 months ago

If you've got a class and you're writing code, trying to get people to eyeball it to see if it's right is probably the clunkiest solution possible.

This isn't for a class so no instructor to go ask for help unfortunately. This is for a distribution company I work at. I believe the code is going to be rewritten in another language but I'm not sure exactly which they are going to use (I believe we use Python, C#, and maybe Javascript). I just needed the logic to be sound so it can be transcribed (by someone else).

I do need to get a compiler but I couldn't download it at work so I just wrote it in notepad++ lol.

MichelWeber 3 points 4 months ago

go to https://ideone.com/ and you can run your code and test it.

You can select the language among many.

[comment deleted]
tragiktimes101 submitter 1 Build 1 point 4 months ago

If it's any other scenario, I'm glad I don't work there. Because this just doesn't bode well on any level.

Currently there is no system to check for errors. We occasionally have people put too many or too few items in boxes so this is just an added check on them, really. I see a shotty system better than none at all. And, yeah, they are the actual programmers so I think they can handle the trasncription. They just didn't really have much insight on the maths involved (I was really excited to get to help with this as it's been a long time since I had a task to do involving code - hard for me to get motivated to code without a purpose).

[comment deleted]
[comment deleted]
tragiktimes101 submitter 1 Build 1 point 4 months ago

Dude, thanks for that. Pretty cool.

Edit: So... it worked with a few mods but for some reason put out "I LOVE BNL" (or something like that) an indefinite amount of times and crashed my browser, lol.

[comment deleted by staff]
tragiktimes101 submitter 1 Build 1 point 4 months ago

It's only a note so not really, but now that I see it I am annoyed, lol.

Fixed*