Homework Help!

Hey all! Need help with some homework... basically i had to build a program where you input your name, weight, and minutes for four activities ... i then had it calculate calories burned as well. on my program it brings up <iomanip> chart for each category... i need to get the time spent category to show hours:minutes and not just the minutes... this is what i have so far... everything is good but when i run it... the time is still in minutes for each individual event

// <Steven Kidwell>
// Sample program to show calories burned and time in each event
// CSCI 1010 Programming Assignment 3

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

int main()
{
int w;
int bm;
int rm;
int wm;
int wlm;
int bh;
int rh;
int wh;
int wlh;
double bc;
double rc;
double wc;
double wlc;
int hours;
int minutes;
double cals;
double const badrate = .044;
double const runrate = .087;
double const walkrate = .036;
double const wlrate = .042;
char fname[10], lname[15];

// Input all data and information
cout << "Please enter your first and last name: ";
cin >> fname >> lname;
cout << "Please enter your weight: ";
cin >> w;
cout << "Please enter the minutes spent playing badminton: ";
cin >> bm;
cout << "Please enter the minutes spent running: ";
cin >> rm;
cout << "Please enter the minutes spent walking: ";
cin >> wm;
cout << "Please enter the minutes spent lifting weights: ";
cin >> wlm;
cout << endl;
cout << "Here are the results for: ";
cout << fname << " " << lname << endl;
cout << endl;

//Calculations for minutes per event
bc = w * badrate * bm;
rc = w * runrate * rm;
wc = w * walkrate * wm;
wlc = w * wlrate * wlm;

//Calculations for time spent in hours/minutes and calories burned
hours = (bm + rm + wm + wlm) / 60;
minutes = (bm + rm + wm + wlm) % 60;
cals = bc + rc + wc + wlc;

//Table showing activity, time, and calories burned
cout << "Activity" << setw(15) << "Time" << setw(10) << "Calories" << endl;
cout << "---------------------------------" << endl;
cout << "Badminton" << setw(13) << right << bm << setw(11) << fixed << setprecision(3) << bc << endl;
cout << "Running" << setw(15) << right << rm << setw(11) << fixed << setprecision(3) << rc << endl;
cout << "Walking" << setw(15) << right << wm << setw(11) << fixed << setprecision(3) << wc << endl;
cout << "Weights" << setw(15) << right << wlm << setw(11) << fixed << setprecision(3) << wlc << endl;
cout << "---------------------------------" << endl;
cout << "Total" << setw(15) << right << hours << ":" << minutes << setw(10) << cals << endl;

system("pause");
return 0;

}

v/r

steven
Last edited on
looks pretty good.
you need to change all your print statements to do what the total one did if you want hours.

so you need to take like badminton ..
double bmhours = bm/60
cout << blah blah << bmhours << ":" << bm << etc...

its exactly the same things you already did, just need more of it.

hint: you can compute results and write them inside cout if they are 'throwaway' results...
cout << blah blah << bm/60 << ":" bm%60 << etc


awesome! thank you so much for the reply... i've been typing different things for hours and i knew it is much easier than i thought. lol
I suggest to add function to display time to simplify code.
You can contact us live at http://www.assignments.me/cpp.html for help with assignment. starting from $10

Last edited on
Topic archived. No new replies allowed.