We have to write a small program that takes some user input(height, weight, age)
ID: 3629008 • Letter: W
Question
We have to write a small program that takes some user input(height, weight, age) and then calculates and displays some other quantities to the user(hat size, jacket size, etc).The user is prompted at the end if he want to hav another go, and he can choose to run it as many times as he wants.
I have something along the lines of:
do
{
//the calculations and outputs are all inside here.everything works fine.here is an example for the jacketSize variable.
jacketSize = (height*weight) / 288;
if(age >= 30){
jacketSize += (1/8.0)* ((age - 30)/10) ; }
System.out.println(jacketSize);
}
while(user_retry == true);
After the user is done running the loop as much as he wants, I have to output the largest and second largest jacketSize. My question is, how can I keep track of all the jacketSize values that I get for each loop run. Wont the variable just be overwritten everytime the loop is run?
Explanation / Answer
please rate - thanks
do it this way
initialize 2 variables
biggest for the largest size, biggest2 for the 2nd largest size
int biggest=-999,biggest2=-999;
do
{
//the calculations and outputs are all inside here.everything works fine.here is an example for the jacketSize variable.
jacketSize = (height*weight) / 288;
if(age >= 30){
jacketSize += (1/8.0)* ((age - 30)/10) ; }
System.out.println(jacketSize);
if(jacketSize>biggest)
{biggest2=biggest;
biggest=jacketSize;
}
else if(jacketSize>biggest2)
{biggest2=jacketSize;
}
}
while(user_retry == true);
System.out.println("The biggest size is "+biggest);
System.out.println("The second biggest size is "+biggest2);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.