Need help on how to set this one up

Hey, guys. I need help with this question: A piece of wire is to be bent in the form of a rectangle to put around a picture frame. The length of the picture frame is 1.5 times the width. Write a program that prompts the user to input the length of the wire and then outputs the length and the width of the picture frame.

I'm not sure if I should code something that has got to do with the perimeter. Thanks for your time!

Last edited on
ok so I've written this with some help from others. Do you think it represents what the question is trying to ask?

#include <iostream>

using namespace std;

int main()
{

double length;
double width;

cout << "Input the length of the wire:";
cin >> length;
cout << endl;

width = length / 1.5;

cout << "length = " << length << endl;
cout << "width = " << width << endl;

return 0;


}
closed account (iGLbpfjN)
I don't think it's right... Because, the user inputs the lenght of the wire, not the the lenght of the picture frame.

The lenght of wire (LW) is equal to the perimeter of the picture frame (2 * length + 2 * width).
LW = 2 * length + 2 * width

But you know that length = 1.5 * width, so:
LW = 2 * 1.5 * width + 2 * width
width = LW / 5
width = 0.2 * LW

So:
length = 1.5 * 0.2 * LW
length = 0.3 * LW

The code'll be something like:
1
2
3
4
5
6
7
8
9
10
double LW, length, width;

cin >> LW;

length = 0.3 * LW;
width = 0.2 * LW;

cout << "Length: " << length << endl;
cout << "Width: " << width << endl;
 
Ok so a quick question.

How did you get to width = LW/5?
and how did you get to Width = 0.2 * LW?
and finally, how is length = 0.3?

Let LW be length of wire input by user.
The perimeter of rectangle will be equal of LW.

LW = 2(l + w)
But , l = 1.5w......(Equation 1)
LW = 2(1.5w + w)
LW = 5w
Therefore
w= LW/5 = 0.2LW

Substituting value of w in equation 1.
l = 1.5(0.2LW)
l= 0.3 LW
Ok. So I got this. What do you think?


#include <iostream>

using namespace std;

int main()
{

double length;
double width;
double Lengthofwire;

cout << "Input the length of the wire:";
cin >> Lengthofwire;
cout << endl;

// formula to get length and width for picture frame
width = Lengthofwire / 5;
length = 1.5 * width;

cout << "length = " << length << endl;
cout << "width= " << width << endl;

return 0;


}
Topic archived. No new replies allowed.