Homework: Balance Question

iI don't know how to do this question

Page 1 of 1

2 Replies - 5980 Views - Last Post: 28 June 2009 - 07:00 AM Rate Topic: -----

#1 LeoTey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-June 09

Homework: Balance Question

Post icon  Posted 28 June 2009 - 05:14 AM

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.............

Is This A Good Question/Topic? 0
  • +

Replies To: Homework: Balance Question

#2 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: Homework: Balance Question

Posted 28 June 2009 - 05:23 AM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 556
  • Joined: 24-July 08

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
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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1