Thread: Assistance with problem

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    1

    Assistance with problem

    Write a program to calculate target heart rate during fitness training. This program has two functions: main and heartRateCalculator. Please do the following:
    (a) In the main function, ask the user to enter age and resting heart rate.
    (b) In the main function, invoke the heartRateCalculator function. Pass the age and resting heart rate as arguments.
    (c) In the heartRateCalculator function, write code to calculate target heart rate during fitness training with the following formula: Target hart rate = (220 – age – resting heart rate) * 0.4 + resting heart rate
    Display target heart rate.
    (d) Don’t forget to write the necessary function prototype statement.

    My program
    Code:
    #include <cstdlib> 
    #include <iostream> 
    using namespace std; 
    void heartRateCalculator (double,double); 
    int main() 
    { 
        double age = 0.0; 
        double restingHeartRate = 0.0; 
        double heartRateCalculator = 0.0; 
        double TargetHeartRate= 0.0; 
         
        cout << "Please enter your age:"; 
        cin >> age; 
        cout << "What is your resting heart rate?:"; 
        cin >> restingHeartRate; 
        heartRateCalculator (age,restingHeartRate); 
       
         
        system("pause"); 
        return 0; 
    } 
     
    void heartRateCalculator (double age,double restingHeartRate) 
    { 
        double heartRateCalculator = 0.0; 
         
        TargetHeartRate = (220-age-restingHeartrate)*0.4 + restingHeartRate; 
        cout << "Target Heart Rate:" << TargetHeartRate <<endl; 
         
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,485
    > double TargetHeartRate= 0.0;
    Move this line inside your function.

    Next time, ask an actual question (you know, it ends with a ?).
    Don't just dump your assignment and code, and hope we can guess what you're thinking.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    (d) Don’t forget to write the necessary function prototype statement.
    Really?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,674
    Am I the only one who thinks this is a bad function prototype.


    Code:
    void heartRateCalculator (double,double);
    I think this would be better in most ways.

    Code:
    double heartRateCalculator (double age, double restingHeartRate);
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 5x5 Array Problem - Any assistance appreciated...
    By Drezden in forum C Programming
    Replies: 3
    Last Post: 06-28-2013, 09:58 AM
  2. Gradebook Program - Small Problem, Need Assistance
    By CaitlynCraft in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 09:51 PM
  3. Need some assistance
    By gcpatton in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2006, 08:50 PM
  4. Need Some Assistance
    By vodlum in forum C++ Programming
    Replies: 6
    Last Post: 09-16-2005, 02:57 PM
  5. Assistance Please?
    By Silence in forum C Programming
    Replies: 7
    Last Post: 05-11-2002, 06:14 PM