Need help on how to set this one up

Sep 4, 2016 at 11:35pm
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 Sep 5, 2016 at 12:18am
Sep 4, 2016 at 11:37pm
Are you having problems with the code itself or how to start coding?
Sep 4, 2016 at 11:44pm
How to start coding it.
Last edited on Sep 4, 2016 at 11:44pm
Sep 4, 2016 at 11:50pm
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?
Sep 5, 2016 at 12:03am
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 Sep 5, 2016 at 12:03am
Sep 5, 2016 at 12:07am
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!
Sep 5, 2016 at 12:11am
to output the width and length it would be:

cout << length << width << endl;

But the question asks to output the length and width.
Sep 5, 2016 at 12:14am
So you could code it like this:

1
2
cout<<"length = "<<length<<endl;
cout<<"width = "<<width<<endl;
Sep 5, 2016 at 12:36am
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;


}
Sep 5, 2016 at 12:42am
Yes I think it answers the problem!
Sep 5, 2016 at 12:59am
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!
Sep 5, 2016 at 1:05am
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!
Sep 5, 2016 at 6:03pm
@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 Sep 5, 2016 at 6:04pm
Sep 6, 2016 at 12:14am
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.