Sinisterly
[C++] BMR Calculator - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C)
+--- Thread: [C++] BMR Calculator (/Thread-C-BMR-Calculator)

Pages: 1 2


[C++] BMR Calculator - BreShiE - 02-02-2013

After taking a look at one of my college systems, it described a system and formulas to create a BMR (Basal Metobolic Rate) calculator, and I misread the assignment thinking I had to code the system, which I didn't. But I coded the system anyway, so I though I'd share it with you here! I've tested it for both male and female, several heights and weight, and as far as I can tell it runs perfectly! (P.S if anyone knows how to add an icon to console applications, please let me know)

The Code:
Spoiler:
[Image: cOkhny1.png]



The Program:
http://www.sendspace.com/file/69m58e

Let me know what you think! Smile


RE: [C++] BMR Calculator - Kinanizer - 02-02-2013

I think you deserve the Coder award. Great share man.


RE: [C++] BMR Calculator - KyleFYI - 02-02-2013

Nice of you to post the source Tongue


RE: [C++] BMR Calculator - BreShiE - 02-02-2013

Thanks guys. I'm picking up C++ rather quickly actually. I'm so glad I started learning it in college.


RE: [C++] BMR Calculator - cxS - 02-25-2013

There's just about twice as much code here from what is really necessary.


RE: [C++] BMR Calculator - Dong - 09-14-2013

Not bad, but there is a snippet of code in there that is repeated twice for no real reason. Hopefully by now you've learned to optimize a program such as this. Nonetheless, nice!


RE: [C++] BMR Calculator - cxS - 09-14-2013

(09-14-2013, 12:40 AM)Aristotle Wrote: Not bad, but there is a snippet of code in there that is repeated twice for no real reason. Hopefully by now you've learned to optimize a program such as this. Nonetheless, nice!

lol, I pointed this out months ago.


RE: [C++] BMR Calculator - Dong - 09-14-2013

(09-14-2013, 12:43 AM)cxS Wrote: lol, I pointed this out months ago.

My mistake, I thought the thread had said it had 0 replies! Next time, I'll be sure to check.


RE: [C++] BMR Calculator - cxS - 12-10-2013

Here's a way you can encapsulate it's functionality:
Code:
#include <iostream> #include <cstdint> enum GENDER { MALE, FEMALE }; struct BMR { public: BMR(GENDER gender) : sex(gender), years(0), weight_kg(0), height_cm(0), last_bmr(0) { } BMR(GENDER gender, float weight, float height, uint32_t age) : sex(gender) { weight_kg = weight; height_cm = height; years = age; last_bmr = 10 * weight + 6.25 * height - 5 * age + (gender == MALE ? 5 : -161); } uint32_t operator() () { return getBmr(); } uint32_t last_bmr; uint32_t years; float weight_kg; float height_cm; GENDER sex; private: uint32_t getBmr() { return (last_bmr = 10 * weight_kg + 6.25 * height_cm - 5 * years + (sex == MALE ? 5 : -161)); } }; int main() { BMR bmr(MALE, 100, 180, 27); std::cout << bmr() << std::endl; bmr.weight_kg = 80; std::cout << bmr() << std::endl; }

Disregarding the user input parsing, there's an example of its usage as well. If you wanted it to say "BMR: {value} or something like that, obviously you'd overload the << operator.


RE: [C++] BMR Calculator - Oni - 12-10-2013

Code-critique, almost a year late. Tongue