need help adding feeting and inches together

#include <iostream>

using namespace std; // introduces namespace std

int main ()
{
         int ft1, in1;
         int ft2, in2;
         int ft3, in3;
         int total;
         int fft;
         int iin;
         
         
         cout << "The measurement in feet and inches" << endl;
         cin >> ft1 >> in1 >> ft2 >> in2;
         
         cout << ft1 << " feet, " << in1 << " inches " << endl;
         cout << ft2 << " feet, " << in2 << " inches " << endl;
         
         
         cout << "The total in feet and inches." << endl;
         cin >> ft1 >> in1 >>ft2 >> in2;
         
         cout << ft1 + ft2 << " feet, " << in1 + in2 << " inches " << endl;
         
         total=ft3+in3;
         fft=total;
         iin=total;
         
         cout << "The measurement as a fraction of a foot." << endl;
         cin >> total;
        
         
         
         system ("pause");
         return 0;
}

Uhhh I will help u.. I have noticed u got the math wrong.. U havent thought of what happens if the person enters 12, 24, 36 inches (multiples of 12).. then to convert that to feet.. What if the person enters 15 (its greater than 12 but not a multiple)..

U see where Im going with this? Also you are declaring variables that arent being used.. and u are calling for them.. In your calculations, fft, iin was not used.. neither were ft3 and in3.. so there for when u call for total, itll always equal 0.
This is because no operations were performed on it.. nor does it hold any values.

anyway I just took the time out of my life (1.5hrs) to write the code hoping you will understand it and to teach others.. I have to say it was quite difficult to understand what to do when they enter a number larger than 12 but not a multiple of 12.. and what to do if they enter a number that is 12 or a multiple of it.. also what to do if the number is less than 12...

here is the code for future people.. I found it quite INTERESTING!! Because I couldnt find a way to determine if the numbers were whole or not when divided without going through a whole bunch of crap.

#include <iostream>
#include <windows.h>
#include <cmath>
#include <math.h>

using namespace std;

int feet1, feet2, inches1, inches2, inchestotal;
double modinches1, modinches2, feettotal;

int main()
{
    cout<<"Enter the amount of feet: ";
    cin>> feet1;
    cin.ignore();
    cout<<"Enter the amount of inches: ";
    cin>> inches1;
    cin.ignore();
    cout<<"Enter the second amount of feet: ";
    cin>> feet2;
    cin.ignore();
    cout<<"Enter the second amount of inches: ";
    cin>> inches2;
    cin.ignore();
    
    modinches1 = inches1%12;  //Modulo gives the remainder of a/b.. so example a = 12, b = 3, remainder is 0. a = 12, b = 9, ans = 1 r 3
    modinches2 = inches2%12;
    double modinchestotal = ((inches1 + inches2)%12);
    
    if ((modinches1 < 1) && (modinches2 < 1)) //If both inches are divisible by 12 (a whole number) then...
    {
      feettotal = (feet1 + feet2);
      inchestotal = ((inches1 + inches2)/12);
      double feetgrandtotal = (feettotal + inchestotal);
      cout<<feetgrandtotal<<" feet "<< modinchestotal<<" inches\n";
    }
    else if ((modinches1 >= 1) && (modinches2 >= 1))  //Else if both inches aren't divisible by 12 (a decimal) then...
    {
         inchestotal = (inches1 + inches2);
         int inchesdivis = ((inchestotal)/12);
         feettotal = ((feet1 + feet2) + inchesdivis);
         int modinchesgrandtotal = ((inches1 + inches2)%12);
         
         cout<<feettotal<<" feet "<<modinchesgrandtotal<<" inches\n";
    }
    else if ((modinches1 < 1) && (modinches2 >= 1))  //Else if inches1 is divible by 12 but inches2 maybe then...
    {
         inchestotal = (inches1 + inches2);
         int inchesdivis = ((inchestotal)/12);
         feettotal = ((feet1 + feet2) + inchesdivis);
         int modinchesgrandtotal = ((inches1 + inches2)%12);
         
         cout<<feettotal<<" feet "<<modinchesgrandtotal<<" inches\n";
    }
    else if ((modinches1 < 1) && (modinches2 > 1))  //Else if inches1 is divisible by 12 but inches2 is NOT then...
    {
         inchestotal = (inches1 + inches2);
         int inchesdivis = ((inchestotal)/12);
         feettotal = ((feet1 + feet2) + inchesdivis);
         int modinchesgrandtotal = ((inches1 + inches2)%12);
         
         cout<<feettotal<<" feet "<<modinchesgrandtotal<<" inches\n";
    }
    else if ((modinches1 > 1) && (modinches2 <= 1)) //Else if inches1 isnt divisible by 12 but inches2 maybe then...
    {
         inchestotal = (inches1 + inches2);
         int inchesdivis = ((inchestotal)/12);
         feettotal = ((feet1 + feet2) + inchesdivis);
         int modinchesgrandtotal = ((inches1 + inches2)%12);
         
         cout<<feettotal<<" feet "<<modinchesgrandtotal<<" inches\n";
    }  
    else if ((modinches1 > 1) && (modinches2 < 1)) //Else if inches1 isnt divisible by 12 but inches2 IS then...
    {
         inchestotal = (inches1 + inches2);
         int inchesdivis = ((inchestotal)/12);
         feettotal = ((feet1 + feet2) + inchesdivis);
         int modinchesgrandtotal = ((inches1 + inches2)%12);
         
         cout<<feettotal<<" feet "<<modinchesgrandtotal<<" inches\n";
    }
    
    system("Pause");
    return 0;    
}

More Simplified.. And Im sorry for the second post.. But this Idea just came to my head..

#include <iostream>
#include <windows.h>
#include <cmath>
#include <math.h>

using namespace std;

int feet1, feet2, inches1, inches2, inchestotal;
double modinches1, modinches2, feettotal;

int main()
{
    cout<<"Enter the amount of feet: ";
    cin>> feet1;
    cin.ignore();
    cout<<"Enter the amount of inches: ";
    cin>> inches1;
    cin.ignore();
    cout<<"Enter the second amount of feet: ";
    cin>> feet2;
    cin.ignore();
    cout<<"Enter the second amount of inches: ";
    cin>> inches2;
    cin.ignore();
    
    modinches1 = inches1%12;
    modinches2 = inches2%12;
    double modinchestotal = ((inches1 + inches2)%12);
    
    if ((modinches1 < 1) && (modinches2 < 1)) //If both inches are divisible by 12 (a whole number) then...
    {
      feettotal = (feet1 + feet2);
      inchestotal = ((inches1 + inches2)/12);
      double feetgrandtotal = (feettotal + inchestotal);
      cout<<feetgrandtotal<<" feet "<< modinchestotal<<" inches\n";
    }
    else //Just Else.. or U can use ((modinches1 < 1) && (modinches2 < 1))||((modinches1 < 1) && (modinches2 < 1))||((modinches1 > 1) && (modinches2 <= 1))  Etc.. etc.. etc... Notice the || operator between them.. meh just stick to Else..
    {
         inchestotal = (inches1 + inches2);
         int inchesdivis = ((inchestotal)/12);
         feettotal = ((feet1 + feet2) + inchesdivis);
         int modinchesgrandtotal = ((inches1 + inches2)%12);
         
         cout<<feettotal<<" feet "<<modinchesgrandtotal<<" inches\n";
    }
    
    system("Pause");
    return 0;    
}

The right way to handle such things is to convert to an internal representation which will easily handle any of the input values. In this case: inches. Then you do the math on the internal representation, then only as needed, convert back to the external representation using the mod operator as suggested. You are suggesting a similar thing, but using feet, which makes the math much more difficult. (You could use meters internally: The only difference would be how you convert to the internal and how you convert to the external representation)

Both answers have the same problem:
1) way too complex for the question asked. This whole program from main() to return can be written in less than 12 lines.
2) Seems to be full working code which means cheating! And we do NOT condone cheating. On these forums we help, we don't do it for them.

wow... in 12 lines?? :O :S I'd like to see that..
And too complexed?? How? Sorry for posting the whole code. I just thought he showed effort. Maybe not enough I guess. Ill think next time before posting code..

wow... in 12 lines?? :O :S I'd like to see that..
And too complexed?? How? Sorry for posting the whole code. I just thought he showed effort. Maybe not enough I guess. Ill think next time before posting code..

I'll do it in python, which I enjoy, and which will certainly not cheat a C++ student out of doing the work...

def getInput(prompt = 'Please enter feet:inches '):
    feet,inches = raw_input(prompt).strip().split(':')
    return int(inches) + 12*(int(feet))

def printFeetAndInches(inches):
   print("%d feet, %d inches"%(divmod(inches,12)))

def main():
    lhs = getInput()
    rhs = getInput()
    printFeetAndInches(lhs + rhs)

if __name__ == "__main__":
    main()

(Though I see it took 14 lines)

>> feet,inches = raw_input(prompt).strip().split(':') don't you just love python :)

:S is this not the c++ forum?

:S is this not the c++ forum?

It is the C++ forum... where someone was recently mildly chastised for doing too much work for the OP.
I chose to use Python because it ...will certainly not cheat a C++ student out of doing the work... The point was to show program flow and reinforce the post I'd made earlier that the internal representation should be easy to manipulate: Inches make more sense than "inches and feet" as the internal rep. If OP is clever enough to 'steal' my python code by rewriting it in C++, that's ok too: The exercise of writing actual C++ code is the point, regardless of how the code you must write was described to you. ... And to show that by doing things in an efficient manner, you could in fact get the job done in about a dozen lines of code. C++ is only slightly more verbose than Python, so "about a dozen" lines should be sufficient in C++ too.

Plus, of course, I really do enjoy Python, so it was a chance to show off some of the excellent features of that language.

okay, I thank everyone for helping me with this, but I am more confused as I was before. This is the first program I have ever had to write. I am trying to get 5ft 7in and 6ft 8in add up to 12ft 3in and also to com out to 12.25.

Please show the code you have now and we can help you out.

#include <iostream>

using namespace std; // introduces namespace std

int main ()
{
         int ft1, in1;
         int ft2, in2;
         int ft3, in3;
         int total;
         int fft;
         int iin;
         
         
         cout << "The measurement in feet and inches" << endl;
         cin >> ft1 >> in1 >> ft2 >> in2;
         
         cout << ft1 << " feet, " << in1 << " inches " << endl;
         cout << ft2 << " feet, " << in2 << " inches " << endl;
         
         
         cout << "The total in feet and inches." << endl;
         cin >> ft1 >> in1 >>ft2 >> in2;
         
        
         
         cout << ft1 + ft2 << " feet, " << in1 + in2 << " inches " << endl;
         
         if ((in1+in2)>12);
         (ft3)%12;
         (in3)/12;
         fft=total;
         iin=total;
         
         cout << "The measurement as a fraction of a foot." << endl;
         cin >> total;
        
         
         
         system ("pause");
         return 0;
}

12ft 3in and also to com out to 12.25

for that you would need a double.. pass the inches into a double type variable..

12 ft, 3in are both integers and hold no decimal places. if you do double x = inches/12 you should get the .xxxx u wanted. Just figure out the numbers to enter thats all. and implement

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.