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
Are you having problems with the code itself or how to start coding?
How to start coding it.
Last edited on
Well it shouldn't have anything to do with the perimeter. The rough ideia should be:

-ask the user to enter the length

-output length
-output width (length/1,5)

Do you need any more tips?
This is what I have so far. I'm not sure about the math I believe.

#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;



return 0;


}
Last edited on
That is right. Only one problem here
width = length \ 1.5;
to divide you should use this / instead of this \.

Now you just need to output the width and length and you are done!
to output the width and length it would be:

cout << length << width << endl;

But the question asks to output the length and width.
So you could code it like this:

1
2
cout<<"length = "<<length<<endl;
cout<<"width = "<<width<<endl;
ok. Great! Thanks. So I have this now:

Do you think this should answer the question I originally posted?

#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;


}
Yes I think it answers the problem!
You were a great help. This is why the internet is awesome. People are just patient. I'm new to c++. Just started my first semester. Thanks!
No problem it was a pleasure! If you need help with anything else you could send me a pm, I am also new so it helps us both.
Happy coding!
@Leo1994,

I hate to spoil your excitement, but instructions say to get user input for length of wire not length. Once you have length of wire solve for width and multiply width by 1.5 to get length. Then output the width and length.

Sorry about that,

Andy
Last edited on
Hey, Andy.

I have this now. 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.