I am new to c++ and I am trying to write a simple win32 console application to calculate the sum of two angles. Basically the user inputs the angles in degree's, minutes, and seconds, and the program calculates the sum with minutes and seconds carrying over correctly when necessary. I was given a set of 5 different scenarios to test the program. 4 work 100% correctly while the last gets calculated incorrectly, and I can not for the life of me figure out what I've done wrong in the code. Any help would be greatly appreciated.
My program does the first 4 correct the last however comes out to
359 60 0
My code
//**********************************
//
// Angle Calculation
// Calculates the sum of two angles
// Date: 9-19-09
//
//**********************************
#include<iostream>
using namespace std;
// Assigning constants
const int Degree_Max = 360;
const int Min_Max = 60;
const int Sec_Max = 60;
int main()
{
// Declaring variables
int deg1, deg2;
int min1, min2, min3;
int sec1, sec2, sec3;
// First angle input
cout << "Please enter the first angle( in degree's, minute's, and second's ): " << endl;
cin >> deg1 >> min1 >> sec1;
cout << "Angle 1 = " << deg1 << " degree's, " << min1 << " minute's " << sec1 << " second's " << endl;
// Second angle input
cout << "Please enter the second angle ( in degree's, minute's, and second's ): " << endl;
cin >> deg2 >> min2 >> sec2;
cout << "Angle 2 = " << deg2 << " degree's, " << min2 << " minute's " << sec2 << " second's " << endl;
// Declaring third variable to allow for carry over in math ops
I'm unsure what you mean. In none of the lectures have I heard anything about a way to "implement 'carry' " other than creative use of modulus and integer division. So if this is a term I have not yet learned then I am unable to use it at this point, the same also goes for 'if' statements.
Again 99% of the time the calculations are carrying over correctly, it's just that one occurrence where zeros are returned for all three.
navi ... what is different about the last set of inputs vs. the others?
the minutes add up to 60.
perhaps you should look at how your program handles that.
that is what kbw is saying. when minutes >= 60, you need to subtract 60 and 'carry' a 1 over to the
degrees. then, when the degrees add up to >= 360, you need to subtract 360.