Hello :) I need help.
I am having so much trouble with functions. Declaring them and calling them.
I have a program I have to do that I have to declare and call functions of an existing program I have written already.
I'm not asking anyone to do my work for me but I desperately need an example so I can work with it myself. My brain is just blanking out on this and I'm stuck. Hopefully I can get a "Eureka" moment.
These are the functions I'm supposed to declare.
inputNumber - takes a string representing a prompt as an argument, displays the prompt, reads an int value from the console, then returns that value.
calculateCalories - takes a double representing the burn rate, an int representing the weight, and an int representing the number of minutes, and returns the result of multiplying the three numbers together.
displayHeadings - takes no arguments, displays the headings for the table to the console, and does not return a value.
displayLine - takes a string representing an activity, an int representing hours, an int representing minutes, and a double representing calories, displays a formatted line of output to the console, and does not return a value.
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << setprecision(3) << fixed;
cout << "Welcome to Name'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 = 0.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(21) << endl;
cout << "---------------------------------" << endl;
cout << "Badminton " << left << setw(6) << right << minsbadminton / 60 << ":" << minsbadminton % 60 << setw(14) << right << TTLCALBADMINTON << endl;
cout << "Running " << left << setw(8) << right << minsrunning / 60 << ":" << minsrunning % 60 << setw(14) << right << TTLCALRUNNING << endl;
cout << "Walking " << left << setw(8) << right << minswalking / 60 << ":" << minswalking % 60 << setw(14) << right << TTLCALWALKING << endl;
cout << "Weights " << left << setw(8) << right << minsweights / 60 << ":" << minsweights % 60 << setw(14) << right << TTLCALWEIGHTS << endl;
cout << "---------------------------------" << endl;
cout << "Totals " << left << setw(9) << right << totalhours << ":" << minutes << setprecision(2) << setw(15) << right << TTLCALSBURNED << endl;
system("PAUSE");
return 0;
}
|