Okay, so I'm a complete novice to c++, and am having a bit of an issue with this one particular program. I don't want the solution, I just want to know where I am going wrong... so anyway, here is what the program is supposed to do.
User is supposed to input two numbers for example
12 36, which is then supposed to show it as
12 hrs 36 minutes. (I have this part, so don't need help here)
The second part is supposed to drop it down and output it like this 12.36 hrs for the total hours, again, I am good to go here.
My problem is getting the modulus stuff right incase say someone puts 12 75, so that instead of it saying 12.75 hrs it instead rolls over to say 13.15 hrs.
I know that my issue lies somewhere within my math (as I am pretty horrible at math) so any suggestions will be greatly appreciated guys/gals. I'll post my code below, also, it is no where near completed and still needs formatting so don't knock me too hard on it.
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
|
#include <iomanip>
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int hrs, min;
double totaltime;
totaltime=(hrs+min)%60;
cout <<"Please enter your time, ex 12 45 "<<endl<<endl;
cin>>hrs>>min;
cout <<hrs<<" Hours" << setw(3) <<min<<" Minutes" <<endl<<endl;
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(0);
cout << totaltime << min<< " Hours" <<endl; //<<min is to show the 12.<min> for some reason it refuses to show without that.
system("PAUSE");
return EXIT_SUCCESS;
}
|