A balance has the following size weights: 100 lb, 50 lb, 10 lb, 5 lb, and 1 lb. The number of 100 lb and 50 lb weights required to weigh an object weighing weight pounds can be calculated by using the following C++ statements:

// Determine the number of 100 lb weights

w100 = int(weight/100)

// Determine the number of 50 lb weights

w50 = int((weight – w100 * 100)/50)

Using these statements as a starting point, write a C++ program that accepts a weight input from the user and then calculates the number of each type of weight needed to weigh that object.

Can somebody teach me to do this question.............

## 2 Replies - 9641 Views - Last Post: 28 June 2009 - 07:00 AM

##
**Replies To:** Homework: Balance Question

### #3

## Re: Homework: Balance Question

Posted 28 June 2009 - 07:00 AM

Though i agree with the rules, i would like to see some code, i will still give you some logic advice.

Ok, so the user gives you the weight. What you want to do is find out how many 100lb, 50lb, 10lb, 5lb, 1lb weights it will take to make that weight.

This statement

Is just simply telling you how many 100lb weights it would take to get the weight by dividing the weight given by 100.

the 'int' to the right of the '=' is telling the program to only return a whole number.

that should give you enough information to complete this.

Ok, so the user gives you the weight. What you want to do is find out how many 100lb, 50lb, 10lb, 5lb, 1lb weights it will take to make that weight.

This statement

int w100 = int(weight/100);

Is just simply telling you how many 100lb weights it would take to get the weight by dividing the weight given by 100.

the 'int' to the right of the '=' is telling the program to only return a whole number.

that should give you enough information to complete this.

Page 1 of 1