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

  • Thread starter Thread starter Streitsky
  • Start date Start date
  • Tags Tags
    C++ Loop
AI Thread Summary
The discussion revolves around a programming challenge involving user input for height, weight, and age to calculate jacket size. The initial approach considered using an If/Else statement for age adjustments but was deemed inefficient. Instead, a loop was suggested for calculating adjustments based on age, specifically adjusting the jacket size by 1/8 inch for every decade after age 30. The final suggestion was to simplify the adjustment using a formula that calculates the adjustment based on the age, avoiding the need for a loop. The conclusion leans towards using the If/Else statement for a more straightforward solution.
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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
19
Views
1K
Replies
36
Views
3K
Replies
3
Views
4K
Replies
8
Views
2K
Replies
12
Views
2K
Replies
1
Views
2K
Replies
1
Views
7K
Back
Top