Quotient and remainder problems

Hi :) any help with this would be appreciated as I really should know this by now. Kinda sad I'm just not gripping the simple stuff.

I was wondering how I'd go about this. The user inputs the minutes spent in each activity. So-
The program prompts the user to enter how many minutes and they do.

for example:
badminton = 30 mins
running = 20 mins
walking = 45 mins
weight lifting = 20 mins

How would my code look to add up all those minutes to make it into h:mm format?

My professor said I need to use the / and the % functions. He also said it divides by 60. example, 256/60 = 4 hrs with 16 mins as the remainder

I get the basic premise but not how to input this into code.
You have the activities, now all you need is another variable you can call total for example where you sum the minutes in all the activities. It should look like this:

badminton = 30 mins
running = 20 mins
walking = 45 mins
weight lifting = 20 mins
total = badminton + running +walking + weight lifting min

You know from math that dividing the minutes by 60 should give how many hours. So it should look like this: int hours = total / 60; and that minutes is the module so it should be
int minutes = total % 60;

Now you only need to output it.

If you need more tips, dont worry about asking again!
Thank you very much for your response :D

I'm not getting a remainder like I need to or getting it into hh:mm format.

Here's my whole code.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()

{

cout << setprecision(3) << fixed;
cout << "Welcome to Sari's workout calculator!" << endl;
cout << endl;

cout << "Please enter your name: " << endl;
string name;
getline(cin, name);

cout << "Please enter your weight: " << endl;
unsigned int weight;
cin >> weight;
cin.ignore(100, '\n');

cout << "Please enter the minutes spent playing badminton: " << endl;
unsigned int minsbadminton;
cin >> minsbadminton;
cin.ignore(100, '\n');

cout << "Please enter the minutes spent running: " << endl;
unsigned int minsrunning;
cin >> minsrunning;
cin.ignore(100, '\n');

cout << "Please enter the minutes spent walking: " << endl;
unsigned int minswalking;
cin >> minswalking;
cin.ignore(100, '\n');

cout << "Please enter the minutes spent lifting weights: " << endl;
unsigned int minsweights;
cin >> minsweights;
cin.ignore(100, '\n');
cout << endl;

int totalmins = minsbadminton + minsrunning + minswalking + minsweights;
int totalhours = totalmins / 60;
int minutes = totalhours % 60;

const double BADMINTON = .044;
const double RUNNING = 0.087;
const double WALKING = 0.036;
const double WEIGHTS = 0.042;

double TTLCALBADMINTON = BADMINTON * weight * totalmins;
double TTLCALRUNNING = RUNNING * weight * totalmins;
double TTLCALWALKING = WALKING * weight * totalmins;
double TTLCALWEIGHTS = WEIGHTS * weight * totalmins;
double TTLCALSBURNED = TTLCALBADMINTON + TTLCALRUNNING + TTLCALWALKING + TTLCALWEIGHTS;

cout << "Here are the results for " << name << ":" << endl;
cout << endl;
cout << "Activity" << left << setw(10) << right << "Time" << setw(15) << right << "Calories" << setw(20) << endl;
cout << "---------------------------------" << endl;
cout << "Badminton " << left << setw(8) << right << minsbadminton << setw(15) << right << TTLCALBADMINTON << endl;
cout << "Running " << left << setw(10) << right << minsrunning << setw(15) << right << TTLCALRUNNING << endl;
cout << "Walking " << left << setw(10) << right << minswalking << setw(15) << right << TTLCALWALKING << endl;
cout << "Weights " << left << setw(10) << right << minsweights << setw(15) << right << TTLCALWEIGHTS << endl;
cout << "---------------------------------" << endl;
cout << "Totals " << left << setw(11) << right << totalhours << setw(15) << right << TTLCALSBURNED << endl;

system("PAUSE");
return 0;

}

It's kinda driving me crazy at this point that I'm missing something hopefully easy
You want to fix the time on "Totals", am I right?
Yes :) That and the Badminton, running, walking, and weights.
Well for the time in "Totals" you should use instead of totalhours this:

...<<totalhours<<":"<<minutes<<...

thats why you made that variable.
For the others instead of making a variable for each one you could do this for example

...<<minsbadminton/60<<":"<<minsbadminton%60<<...

Hope it helps!
Yay! Thank you that helps a lot! ^_^
Topic archived. No new replies allowed.