Evening everyone, need help and suggestion for creating a program

Hello everyone, I'm new to programming and don't really know how everything works so far, so please don't laugh at me. Well. I'm trying to create a program that would add feet and inches. I already started writing it, however can't understand the basics, how to come up with the function. Please help me out with your suggestions. Thanks in advance

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
#include <iostream>
#include <iomanip>

using namespace std;

int main ( void )
{
    int feet, inches, total, ft_1, in_1, ft_2, in_2;
    
    cout <<"enter feet and inches"<<endl;
    cin>>ft_1>>in_1;
    cout <<"enter feet and inches"<<endl;
    cin>>ft_2>>in_2;
    
    
    feet = (ft_1+ft_2)/12;
    inches = feet%12;
    
    
    
    cout<<"feet="<<"inches="<<endl;
    cin>>feet>>inches;
    
    system ( "pause" );
    return 0;
}
Your program logic seems to be a little messed up here. I'm not sure I entirely understand what you're trying to do here, but I think you mean if your input was:
1
2
5 6
5 2

Then the output would be:
 
feet = 10 inches = 8


In that case, you're going to want to:
1
2
3
4
1) add up ft_1 and ft_2
2) add up in_1 and in_2
3) if in_2 and in_2 are greater than 12, increment the sum of ft_1 and ft_2 by one and subtract 12 from the sum of in_1 and in_2 
4) output your results 

That's exactly what I need, thanks a lot
3) can be changed to
1
2
3
4
5
6
feet = ft_1+ft_2;
    inches = in_1 + in_2;
    temp_in = inches % 12;
    cout << temp_in << endl;
    feet += (inches - temp_in) / 12;
    inches = temp_in;
Thanks again guys, I owe you for this one. I've fixed my code so everything is working fine now. Another question is what should I do to get a result in fraction (with decimal point) ? Any suggestions ?
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
#include <iostream>
#include <iomanip>

using namespace std;

int main ( void )
{
    int feet, inches, ft_1, in_1, ft_2, in_2, temp_in;
    
    cout <<"enter feet and inches"<<endl;
    cin>>ft_1>>in_1;
    cout <<"enter feet and inches"<<endl;
    cin>>ft_2>>in_2;
    
    feet = ft_1+ft_2;
    inches = in_1 + in_2;
    temp_in = inches % 12;
    feet += (inches - temp_in) / 12;
    inches = temp_in; 
   
    cout<<"feet="<<feet<<"inches="<<inches<<endl;
    
    
    system ( "pause" );
    return 0;
}
I don't understand your question. You shouldn't be getting any decimal results since you're input is just integers.

On another note, line 19 is unnecessary, you can just print out temp_in instead of assigning it to inches and then printing out inches.
no no no, everything is fine with the code above, I'm getting the result in feet and inches, however I would also like to get a result in decimals
Last edited on
I realize everything is fine, but you have an unnecessary line of code, and unnecessary lines are usually a bad thing. There's no need for it, so it's worthwhile to cut it out.

And again, what do you mean a result in decimals? Give an example, please.
If you just want inches to be able to have a decimal, research the float and double data types.
Last edited on
With line 19, when adding 10ft 10in + 2ft 2in , the result is 13ft 0in which is correct

Without line 19, when adding 10ft 10in + 2ft 2in, the result is 13ft 12in which is wrong

He bearing in mind this

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

using namespace std;

int main ( void )
{
    int feet, inches, ft_1, in_1, ft_2, in_2, temp_in;
    
    cout <<"enter feet and inches"<<endl;
    cin>>ft_1>>in_1;
    cout <<"enter feet and inches"<<endl;
    cin>>ft_2>>in_2;
    
    feet = ft_1+ft_2;
    inches = in_1 + in_2;
    temp_in = inches % 12;
    feet += (inches - temp_in) / 12;
   
    cout<<"feet="<<feet<<"inches="<<temp_in<<endl;
    
    system ( "pause" );
    return 0;
}

Line 19 was deleted and line 21 changed.

Line 19 is unnecessary in this case, but if you will like to do more coding after it and using this results it is line 19 lets to make code more clear.
Last edited on
Got it, thank you guys
Topic archived. No new replies allowed.