Knowledge speaks, but wisdom listens.
- Jimi Hendrix
News
Site News
Latest Comments
Affiliates
Proxies
Contribute!
Chat
Tutorials
Newest Articles
Most Popular
Highest Rated
Latest Comments
Code Samples
Newest Code
Most Popular
Highest Rated
Latest Comments
Blogs
Admins Blog
Newest Blogs
Most Popular
Highest Rated
Latest Comments
Forums
Latest Posts
Latest Topics
Memberlist
[login]
|
[Register]
Fat Percentage
by: bs0d
Description:
A program written in Visual C++, uses a vod function to calculate percentage of fat by entered calories and grams.
Code:
//Displays fat calories and fat percentage #include
using namespace std; //function prototype void calcFatInfo(int, int, int &, float &); int main() { int totalCal = 0; int fatGrams = 0; int fatCal = 0; float fatPercent = 0.0; //enter input data cout << "Total calories: "; cin >> totalCal; cout << "Grams of fat: "; cin >> fatGrams; //validate input data if (totalCal >= 0 && fatGrams >= 0) { //validate data calcFatInfo(totalCal, fatGrams, fatCal, fatPercent); cout << fixed; cout.precision(0); cout << "Fat calories: " << fatCal << endl; cout << "Fat percentage: " << fatPercent << "%" << endl; } else //invalid data cout << "Input error" << endl; //end if return 0; } //end of main function //*****program-defined functions***** void calcFatInfo(int tCal, int grams, int &fCal, float &fPer) { //calculate fat calories and fat percentage fCal = grams * 9; fPer = float(fCal) / float(tCal) * 100; } //end of calcFatInfo function
No Comments for this page.
You Must be
signed in
or a
member
to comment.
Code Stats
8,658
Views
0
Total Comments
0
Rating of 5 (
Votes)
Code Options
·
Login to Rate This Code
·
Login to Post a Comment
·
Read more by this author
Related
·
Open and Write System Call
·
Bit Multiplication
·
Hello World
·
Gross Pay
·
Commission
"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy
|
Internet Rank