Sep 4, 2016 at 11:35pm UTC
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 UTC
Sep 4, 2016 at 11:37pm UTC
Are you having problems with the code itself or how to start coding?
Sep 4, 2016 at 11:44pm UTC
How to start coding it.
Last edited on Sep 4, 2016 at 11:44pm UTC
Sep 4, 2016 at 11:50pm UTC
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 UTC
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 UTC
Sep 5, 2016 at 12:11am UTC
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:36am UTC
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 UTC
Yes I think it answers the problem!
Sep 5, 2016 at 12:59am UTC
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 UTC
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 UTC
@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 UTC
Sep 6, 2016 at 12:14am UTC
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;
}