Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Need help in C++ homework... sorry

Name: Anonymous 2007-02-10 15:55

It is a more of a logic problem then programming and I am having a hard time dealing with it last nigh

"Angles are often measured in degrees (), minutes (‘), and seconds (“). There are 360 degrees in a circle, 60 minutes in one degree, and 60 seconds in one minute. Write a program that reads two angles expressed in degrees, minutes, and seconds from a file, and then calculates and prints their sum. The number of minutes in your answer should be no greater than 59, and the number of seconds in your answer should be no greater than 59. Why do you suppose that’s the case?

this is what in the input file:
3358 14 55
5 24 55

my codes so far
#include <iostream>  // for the cout D M S
#include<fstream>   // needed for openinga file
#include<string>

using namespace std;



main()
{
     
ifstream infile ;
double D1,M1,S1,D2,S2,M2 ;
int t,D,S,M;

infile.open("C:\\Lab4InputFile.txt");

infile >> D1 >> M1 >> S1 >> D2 >> M2 >> S2;


t= ((D1*360*60)+(M1*60)+S1) + ((D2*360*60)+(M2*60)+S2);

cout <<"\n t"<<t<<"\n";

D = t/60/360;             // my main problem is here here
M = t%3600/60;
S = t/3600/60/6;



cout << D1 << "d " << M1 << "m " << S1 << "s " << "+ " << D2 << "d " << M2 << "m " << S2 << "s " ;

cout <<"= "<< D << "d "<< M <<"m "<< S <<"s "  ;

infile.close() ;
cout<< "Done \n";
system("PAUSE");
return 0;
}

thanx

Name: Anonymous 2007-02-10 23:24

Fortunately not. Just do the modulo on degrees alone once you've finished conversions.

finaldeg = finaldeg % 360;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List