Answer to Question #116812 in C++ for hamza

Question #116812
Write a program to calculate the approximate number of times the user's heart has beaten in his/her
lifetime using an average heart rate of 72 beats per minutes. Ask the user to input his/her age. Assume all years
have 365 days.
1
Expert's answer
2020-05-18T17:02:09-0400


#include <iostream>

const long long heart_rate_per_minute = 72;
const int minutes_in_hour = 60;
const int hours_in_day = 24;
const int days_in_year = 365;


int main() {
	using std::cout;
	cout << "Hello user! Please enter your age to see how many beats your heart has made: ";
	int age = 0;
	while (!(std::cin >> age) || age <= 0) {
		std::cin.clear();
		while (!isspace(std::cin.get()))
			continue; // get rid of bad input
		std::cout << "Invalid input! Please repeat: ";
	}
	unsigned long long heart_beats = heart_rate_per_minute * minutes_in_hour * hours_in_day * days_in_year;
	heart_beats *= age;
	cout << "Wow! Unbelievable! Your heart has beaten " << heart_beats << " times already! Isn't it awesome?" << std::endl;
	return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS