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.
1
Expert's answer
2013-02-20T09:00:24-0500
#include<string> #include<iostream> using namespace std; & & int main (){
int w100,w50,w10,w5,w1,a;
cout<<"enter the weight: "; cin>>a; w100=a/100; a=a-w100*100;
Comments
Leave a comment