Question

Sample session: How many growth ring values are there? 6 Enter ring's distance from the center...

Sample session:

How many growth ring values are there? 6

Enter ring's distance from the center in cm: 1.2

Enter ring's distance from the center in cm: 2.7

Enter ring's distance from the center in cm: 3.2

Enter ring's distance from the center in cm: 3.8

Enter ring's distance from the center in cm: 5.9

Enter ring's distance from the center in cm: 6.3

The greatest growth in one year was 2.1 cm.

In pseudocode Provide a graceful response if the user enters no ring values:

Sample session:

How many growth ring values are there? 0

There are no results because there were no readings.

Homework Answers

Answer #1

int ringNum;

float maxGrowth=0; //Data type is float as this can be fractional

Print("How many growth ring values are there?");

Scan(ringNum); //Input the number of rings in ringNum variable

if(ringNum<2)
   {
       Print("There are no results because there were no readings.");

end;

//We can not find ring growth unless we have two rings

//An exception could be just one ring, but that only gives the diameter of that ring, not the ring growth from the previous ring

//Hence, This case does not need to be handled separately

//If this case is needed, just add the below code

/* if(ringNum==1)
   {
Print("The greatest growth in one year was ",ringVal[0]," cm;
       end;
   }
*/   
   }
  
float ringVal[ringNum]; //Initiate an array of the size of the number of rings
  
for(i = 0 to ringNum) //Input all values of rings
{
       Print("Enter ring's distance from the center in cm");
       Scan(ringVal[i]);

}
  
if(ringNum>1)
{
       for(i = 1 to ringNum) //Note that the loop starts from i=1 and not i=0
       {
           if(max < (ringVal[i]-ringVal[i-1])) // This calculates the maximum growth
           {
               max=ringVal[i]-ringVal[i-1];
           }
       }
       Print("The greatest growth in one year was ",max," cm";
       return 0;

}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions