http://prntscr.com/bjfrwv
http://prntscr.com/bjfrwv @Sachintha What formula would I use to calculate the remaining minutes?
secondsRemaining = input - days *86400 - hours*3600 - minutes*60 Someone said this, but I'm not sure what they meant
Is days, hour and minutes are defined? Show me your full code.
I haven't made it yet. I need a formula for finding the remaining minutes. Here you go. http://prntscr.com/birkvl
days=seconds/86400 hours=seconds/3600 minutes=seconds/60 I have this But I need the remain secs formula
//Ashton Dreiling //Seconds exercise #include <iostream> #include <stdlib.h> using namespace std; //module prototypes void calculateDaysHoursMinsAndRemainSecs (double &Days, double &Hours, double &Minutes, double &remainingSeconds, double seconds); //global constants const int VALUETOCALCULATEDAYS = 86400; const int VALUETOCALCULATEHOURS = 3600; const int VALUETOCALCULATEMINS = 60; int main() { //some variables double Days; double Hours; double Minutes; double remainingSeconds; double seconds; cout << "We are going to have you input an amount of seconds to determine the days, hours, minutes, and remaining seconds." << endl; cout << "Please enter the amount of seconds of your choice." << endl; cin >> seconds; cout << "You said you had " << seconds << endl; cout << "We will now determine the days, hours, minutes, and remaining seconds based off of your input." << endl; //pass variables to calculate days, hours, minutes, and remaining seconds calculateDaysHoursMinsAndRemainSecs(Days, Hours, Minutes, remainingSeconds, seconds); cout << "There are " << Days << " Days" << endl; cout << "There are " << Hours << " Hours" << endl; cout << "There are " << Minutes << " Minutes" << endl; system("Pause"); return 0; } void calculateDaysHoursMinsAndRemainSecs(double &Days, double &Hours, double &Minutes, double &remainingSeconds, double seconds) { Days=(seconds/VALUETOCALCULATEDAYS); Hours=(seconds/VALUETOCALCULATEHOURS); Minutes=(seconds/VALUETOCALCULATEMINS); }
I have this so far (Not done yet) But I need a formula to find the remaining seconds
Ah, so I'm on the right path right? I did the days, hours, and mins right correct? @Sachintha
Your post disappeared? I didn't understand what he meant by input
@Sachintha
I think you have to change the seconds to days, hours, minutes and seconds without total hours, minutes .. gh ex: 54055s = 0 days 15hr 0min 55s If so your equations are wrong. The sec remaining equation is meaning less with your day, minutes, hours variables since it simplifies to: sec's remaining = input - (days+hours+mins) which is wrong.
Here I'll show you what the book says and you decide if the equations are correct or not http://prntscr.com/bjg99u
According to the book your equations are correct.
You use this equation for remaining seconds, sec remaining = seconds%60
seconds%60? @Sachintha
Yes it's the modulus sign. Run the program and check whether it outputs correctly.
Why did you put the type of seconds as double?
In case they put in a decimal.
@Sachintha Do you know how to fix that error tho : p
Change it to int.
Why so?
Because I think it is a data type exception. :3
Would you explain? ^.^ @Sachintha
//Ashton Dreiling //Seconds exercise #include <iostream> #include <stdlib.h> using namespace std; //module prototypes void calculateDaysHoursMinsAndRemainSecs (double &Days, double &Hours, double &Minutes, double &remainingSeconds, int seconds); //global constants const int VALUETOCALCULATEDAYS = 86400; const int VALUETOCALCULATEHOURS = 3600; const int VALUETOCALCULATEMINS = 60; const int VALUETOCALCULATEREMAINMINS = 60; int main() { //some variables double Days; double Hours; double Minutes; double remainingSeconds; int seconds; cout << "We are going to have you input an amount of seconds to determine the days, hours, minutes, and remaining seconds." << endl; cout << "Please enter the amount of seconds of your choice." << endl; cin >> seconds; cout << "You typed in " << seconds << " seconds." << endl; cout << "We will now determine the days, hours, minutes, and remaining seconds based off of your input." << endl; //pass variables to calculate days, hours, minutes, and remaining seconds calculateDaysHoursMinsAndRemainSecs(Days, Hours, Minutes, remainingSeconds, seconds); cout << "There are " << Days << " Days." << endl; cout << "There are " << Hours << " Hours." << endl; cout << "There are " << Minutes << " Minutes." << endl; cout << "There are " << remainingSeconds << " remaining seconds." << endl; system("Pause"); return 0; }//end main void calculateDaysHoursMinsAndRemainSecs(double &Days, double &Hours, double &Minutes, double &remainingSeconds, int seconds) { //Calculating values Days=(seconds/VALUETOCALCULATEDAYS); Hours=(seconds/VALUETOCALCULATEHOURS); Minutes=(seconds/VALUETOCALCULATEMINS); remainingSeconds=(seconds % VALUETOCALCULATEREMAINMINS); }//end calculateDaysHoursMinsAndRemainSecs
@Sachintha Alright. Here is finished product. Type if 86,400 when you run. Tell me if there are any logic errors when you run. : )
I am getting some other errors. Did it work on your compiler?
Yes
@Sachintha
I tried it on another compiler. It works perfectly. :D
Join our real-time social learning platform and learn together with your friends!