Division Error

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#import <iostream>
#include <sstream>
#include <iomanip>
using namespace std;

class Measurement
{
      float thou, inch, foot, yard, chain, furlong, mile, league;
      public:
             void setThou(int);
             void setInch(int);
             void setFoot(int);
             void setYard(int);
             void setChain(int);
             void setFurlong(int);
             void setMile(int);
             void setLeague(int);
             double getThou();
             double getInch();
             double getFoot();
             double getYard();
             double getChain();
             double getFurlong();
             double getMile();
             double getLeague();
};

void Measurement::setThou(int in)
{
     thou = in;
     inch = thou / 1000;
     foot = inch / 12;
     yard = foot / 3;
     chain = yard / 22;
     furlong = chain / 10;
     mile = furlong / 8;
     league = mile / 3;
}

void Measurement::setInch(int in)
{
     inch = in;
     thou = inch * 1000;
     foot = inch / 12;
     yard = foot / 3;
     chain = yard / 22;
     furlong = chain / 10;
     mile = furlong / 8;
     league = mile / 3;
}

void Measurement::setFoot(int in)
{
     foot = in;
     thou = inch * 1000;
     inch = foot * 12;
     yard = foot / 3;
     chain = yard / 22;
     furlong = chain / 10;
     mile = furlong / 8;
     league = mile / 3;
}

void Measurement::setYard(int in)
{
     yard = in;
     thou = inch * 1000;
     inch = foot * 12;
     foot = yard * 3;
     chain = yard / 22;
     furlong = chain / 10;
     mile = furlong / 8;
     league = mile / 3;
}

void Measurement::setChain(int in)
{
     chain = in;
     thou = inch * 1000;
     inch = foot * 12;
     foot = yard * 3;
     yard = chain * 22;
     furlong = chain / 10;
     mile = furlong / 8;
     league = mile / 3;
}

void Measurement::setFurlong(int in)
{
     furlong = in;
     thou = inch * 1000;
     inch = foot * 12;
     foot = yard * 3;
     yard = chain * 22;
     chain = furlong * 10;
     mile = furlong / 8;
     league = mile / 3;
}

void Measurement::setMile(int in)
{
     mile = in;
     thou = inch * 1000;
     inch = foot * 12;
     foot = yard * 3;
     yard = chain * 22;
     chain = furlong * 10;
     furlong = mile * 8;
     league = mile / 3;
}

void Measurement::setLeague(int in)
{
     league = in;
     thou = inch * 1000;
     inch = foot * 12;
     foot = yard * 3;
     yard = chain * 22;
     chain = furlong * 10;
     furlong = mile * 8;
     mile = league * 3;
}

double Measurement::getThou()
{
       return thou;
}

double Measurement::getInch()
{
       return inch;
}

double Measurement::getFoot()
{
       return foot;
}

double Measurement::getYard()
{
       return yard;
}

double Measurement::getChain()
{
       return chain;
}

double Measurement::getFurlong()
{
       return furlong;
}

double Measurement::getMile()
{
       return mile;
}

double Measurement::getLeague()
{
       return league;
}

int main()
{
    string input, from, to;
    int amt, pos;
    stringstream temp;
    Measurement test;
    
    getline(cin, input);
    pos = input.find(" ");
    stringstream(input) >> amt;
    input.erase(0, pos + 1);
    pos = input.find(" ");
    from = input.substr(0, pos);
    pos = input.find(" ");
    input.erase(0, pos + 4);
    to = input;

    if(from == "thou" || from == "th")
            test.setThou(amt);
    else if(from == "inch" || from == "in")
         test.setInch(amt);
    else if(from == "foot" || from == "ft")
         test.setFoot(amt);
    else if(from == "yard" || from == "yd")
         test.setYard(amt);
    else if(from == "chain" || from == "ch")
         test.setChain(amt);
    else if(from == "furlong" || from == "fur")
         test.setFurlong(amt);
    else if(from == "mile" || from == "mile")
         test.setMile(amt);
    else if(from == "league" || from == "lea")
         test.setLeague(amt);
          
    if(to == "thou" || to == "th")
            cout << setprecision(13) << test.getThou();
    else if(to == "inch" || to == "in")
         cout << setprecision(13) << test.getInch();
    else if(to == "foot" || to == "ft")
         cout << setprecision(13) << test.getFoot();
    else if(to == "yard" || to == "yd")
         cout << setprecision(13) << test.getYard();
    else if(to == "chain" || to == "ch")
         cout << setprecision(13) << test.getChain();
    else if(to == "furlong" || to == "fur")
         cout << setprecision(13) << test.getFurlong();
    else if(to == "mile" || to == "mile")
         cout << setprecision(13) << test.getMile();
    else if(to == "league" || to == "lea")
         cout << setprecision(13) << test.getLeague();
    
    system("pause");
             
}


Yes, I know that system("pause") is the devil incarnate. I'm using it because Dev C++ won't keep the window open. It won't be in the final program. I'm trying to get the float division to 13 decimal places (ie: 0.4166666666667) All I'm getting is 0.4166666567326 and I can't get it any more precise than that!
floats?

I can't even remember the last time I used one of those.

This program doesn't look like it would take much to run, why try to cut down on memory usage with the floats when you could just as easily use a double and you'd have much more precision. You do it with the functions, so give it a try.


If that doesn't work, then I haven't a clue. You may have to use a language like lisp to get a precision over something like 13
Last edited on
Topic archived. No new replies allowed.