Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Demonstate the use of selection and logic. The imperial measurements of mass use

ID: 3917246 • Letter: D

Question

Demonstate the use of selection and logic. The imperial measurements of mass use the following units:

16 ounces equals one pound
14 pounds equals one stone
8 stones equals one hundred weight
20 hundred weights equal one ton

Write a     C program called Imperial that starts with 642341 ounces and works out how many tons, hundred weights, stones, pounds and ounces this is equal to giving priority to the larger units. The program should output results like those below:

642341 ounces is equal to 17 tons, 18 hundred weights, 3 stones, 8 pounds and 5 ounces

Explanation / Answer

Solution:

####Imperial.c######


#include <stdio.h>

/*16 ounces equals one pound
14 pounds equals one stone
8 stones equals one hundred weight
20 hundred weights equal one ton
*/

int main()
{
float ounces = 642341;
float totalTons = ounces/(16*14*8*20); //Converting the total ounces to the tons
int tons = totalTons;
  
float totalHundredWeights = (totalTons - tons) * 20; //Converting remaining tons to hundrerd weights
int hundredWeights = totalHundredWeights;
  
float totalStones = (totalHundredWeights - hundredWeights)*8; //Converting remaining hundred weights to stones
int stones = totalStones;
  
float totalPounds = (totalStones - stones)*14; //Converting remaining stones to pounds
int pounds = totalPounds;
  
float totalOunces = (totalPounds - pounds)*16; //Converting remaining pounds to ounces
int ounce = totalOunces;
  
printf("%d ounces is equal to %d tons, %d hundred weights, %d stones, %d pounds and %d ounces.", ounces,tons,hundredWeights,stones,pounds,ounce);

return 0;
}

Sample Run:

17.92246118.44921117 ounces is equal to 18 tons, 3 hundred weights, 8 stones, 4 pounds and 4195500 ounces.

Note: If you liked the solution then don't forget to hit the like button. If you have any doubt please do comment below.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote