who can do this?

Jun 12, 2012 at 2:29am
Can someone write a program that prompts the user to input a length expressed in centimeters. The program should then convert the length to inches(to the nearest inch) and output the length expressed in yards, feet, and inches, in that order. For example, suppose the input for centimeters is 312. to the nearest inch, 312 centimeters is equal to 123 inches.123 inches would thus be output as:

3yard(s), 1 feet(foot),and 3inc(es)

assume 1yard=36inches, 1feet=12inches and 1inch=2.54centimeters.


I need this program asap please guys!!!
Jun 12, 2012 at 2:39am
This forum is not a homework service.
Jun 12, 2012 at 2:41am
Zhuge, if you cant help me dont reply me....
Jun 12, 2012 at 2:44am
If you want us to do your homework for you, don't post here.
Jun 12, 2012 at 2:49am
Zhuge, if you cant help me dont reply me....


He is trying to.
Last edited on Jun 12, 2012 at 2:49am
Jun 12, 2012 at 2:51am
So where do I post? I'm trying to get help here...
Jun 12, 2012 at 2:56am
So where do I post? I'm trying to get help here...


What code do you have written?
Jun 12, 2012 at 3:03am
none...after our first c++ class the teacher gave couple assignments and asked us to find and do it....he just wants to test our ability to find help...he is still going to teach more
Jun 12, 2012 at 3:10am
1) write a program that will print: "3 yard(s), 1 feet(foot),and 3inch(es)"
2) write a program that will print: "x yard(s), y feet(foot),and z inch(es)" where z, y, and z are variables
3) write a program that will convert a variable c into the proper x, y, and z values where c is in centimeters.
4) write a program that will ask for c
Last edited on Jun 12, 2012 at 3:11am
Jun 12, 2012 at 3:11am
I don't know anything about programming yet, but asking for someone to do it for you isn't a good start. :P
Jun 12, 2012 at 3:21am
The thing with programming, is you have to look at the problem as a set of problems. Break it down into individual tasks, and life will be much easier.

We are very avid on forum goers actually learning something here, so we may come across as "rude" because most of us will not do your homework. We aren't being rude, we are just trying to help you learn. If someone does all your work for you, then what's the point in even taking the class?
Jun 12, 2012 at 3:30am
we just had 1 class, teacher asked us to get help from any source...he knows that we don't have knowledge of what we are into, but he wants us to come out with a result.
Jun 12, 2012 at 3:46am
But surely he didn't want you to hand in somebody else's work. At least try to write something that we can work off of. Refer to the tutorials on this site if your professor really didn't explain anything at all, which I doubt is true.
Jun 12, 2012 at 5:51am
Here, hand this in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

using namespace std;

int main()
{
    cout << "Does the course I'm taking require prerequisites?" << endl << "Please input 1 for yes, and 0 for no" << endl;
    int x;
    cin >> x;
    switch(x)
    case 1:
    {
         cout << "Why am I in this course?";
         break;
    }
    case 2:
    {
        cout << "My teacher is messing with me";
        break;
    }
    default:
    {
        return 1;
        break;
    }
    return 0;
}

Jun 12, 2012 at 6:17am
you are a clown roger
Jun 12, 2012 at 7:22am
The answer is very simple: You are lazy. Instead of fighting the forum you should be LEARNING. Instead of begging for code you should be READING a tutorial or book.

There's a tutorial in this site. Read it. There are more tutorials out there. Read them.
Jun 12, 2012 at 7:31am
I thought I would take up the challenge myself. I did use ints however, so you will be losing accuracy. Try it with doubles to get a more accurate result. I did a few tests, and I think it's working fine, however, I am a noob so be forewarned.

Additionally, I am assuming you are and adult, who is responsible for his/her actions. Therefore, you are well aware of the consequences of taking shortcuts.

Mike

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <stdlib.h>
#include <locale>
#include <iomanip>
using namespace std;
using std::ifstream;
using std::ofstream;
using std::endl;
using std::ios;

const double C_TO_I=0.393700787;

class Dist
{
public:
	Dist(){}
	Dist(int c):centi(c){}
	int temp;
	void convert(){
		inch=centi*C_TO_I;//loss of accuracy here
		feet=0;
		yard=0;
		if(inch>=12){
			temp=inch/12;
			feet=feet+temp;
			inch=inch%12;
		}
	
		if(feet>=3){
			temp=feet/3;
			yard=yard+temp;
			feet=feet%3;
		}
	}
	friend istream& operator>>(istream& in, Dist& d);
	friend ostream& operator<<(ostream& out, Dist& d);

private:
	int centi;
	int yard, feet, inch;
};

int main()
{
	Dist d1;
	char choice;
	do{
		cin>>d1;
		d1.convert();
		cout<<d1;

		cout<<"Another distance? (y/n): ";
		cin>>choice;
	}while(choice=='y' || choice=='Y');

	_getch();
	return 0;
}	
ostream& operator<<(ostream& out, Dist& d){
	out<<"Yards: "<<d.yard<<" Feet: "<<d.feet<<" Inches: "<<d.inch<<endl;
	return out;
}
istream& operator>>(istream& in, Dist& d){
	cout<<"Enter the distance in centimeters: ";
	in>>d.centi;
	while(d.centi<0){
		cout<<"Can't be less than zero, enter again: ";
		in>>d.centi;
	}
	return in;
}
Topic archived. No new replies allowed.