GeekPolice Tech TutorialsLog in

 


Share

descriptionC++ Balance Weight [NEED HELP]

more_horiz
This is the question:
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, how to write a code that accepts a weight input from the user and then calculates the number of each type of weight needed to weigh that object.

This is what i got so far and i am lost:

Code:


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   int weight, w100, w50, w20, w10, w5, w1;

   cout<<"Please enter a weight: ";
   cin>>weight;
   cout<<"The number of weights needed to balance are "<<w100<<w50<<w20<<w10<<w5<<w1<<endl;

   w100 = int(weight/100);
   w50 = int((weight - w100 * 100)/50);
   w20 = int((weight - w100 * 100)/20);
   w10 = int((weight - w100 * 100)/10);
   w5 = int((weight - w100 * 100)/5);
   w1 = int((weight - w100 * 100)/1);

return 0;
}


What am I doing wrong?? I am new to c++! help pls

descriptionRe: C++ Balance Weight [NEED HELP]

more_horiz
Sorry we can't help you with your homework. Ask your teacher.
Permissions in this forum:
You cannot reply to topics in this forum