Calculate Jacket Size with Height, Weight, and Age | C++ Loop Tutorial

  • Context: C/C++ 
  • Thread starter Thread starter Streitsky
  • Start date Start date
  • Tags Tags
    C++ Loop
Click For Summary
SUMMARY

The discussion focuses on calculating jacket size using a formula that incorporates height, weight, and age in C++. The formula for jacket size is defined as height multiplied by weight divided by 288, with an adjustment of 1/8 inch for every decade after the age of 30. The user initially considers using a loop for this calculation but ultimately decides that an If/Else statement may be more efficient. The adjustment logic is clarified, indicating that no adjustment is made for ages ending in 9.

PREREQUISITES
  • Basic understanding of C++ programming
  • Familiarity with conditional statements (If/Else)
  • Knowledge of mathematical operations in programming
  • Understanding of loops in C++
NEXT STEPS
  • Implement the jacket size calculation using C++ functions
  • Explore the use of loops versus conditional statements in C++
  • Learn about the floor function in C++ for rounding calculations
  • Research best practices for user input handling in C++
USEFUL FOR

Beginner C++ programmers, developers working on user input applications, and anyone interested in mathematical programming challenges.

Streitsky
Messages
2
Reaction score
0
Hey guys it my first post, so please be nice :). So I am doing a problem right now and I can decide how to go about it... I am kinda lost right now, I could use an If/Else statement but it would take along time so I decided to use a loop, so here is the problem.

Program asks user to enter height weight and age. (Completed already)

Jacket size = height times weight divided by 288 and then (This is where I am having trouble>>) adjusted 1/8 of an inch for 10 years after 30 (For example adjusted 1/8 of an inch at 40, 50, 60, 70, but not at 39, 49, 59, 69) Thanks for your help
 
Technology news on Phys.org
You could solve this with a loop, but I'd just divide and round:

Code:
if (age < 40)
  adj = 0;
else
  adj = floor(age / 10 - 3) * 1.0/8;
 
hmm yea, maybe I shouldn't loop it, ill try the if else statement thanks
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 36 ·
2
Replies
36
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
8K