Go down


Post by magicm00n on March 1st 2012, 3:18 pm

Hi i want to add this code to my C++ forum that helps users calculate the weights needed to balance.

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:

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

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

   cout<<"Please enter a 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
Active Poster

Female Posts : 1305
Reputation : 217
Language : English
Location : The support forum of Forumotion

Back to top Go down

Re: C++ HELP!

Post by LGforum on March 1st 2012, 3:23 pm

C++ is not a web language. Therefore not in anyway related to forums.
For something like what you are saying on the internet, you'd need to use Javascript. Javascript is similar to C++ in quite a few ways, the same IF,ELSE,FOR,WHILE structures.

Male Posts : 2263
Reputation : 260
Language : English
Location : UK


Back to top Go down

Re: C++ HELP!

Post by Sanket on March 1st 2012, 3:24 pm

Sorry, only questions related to Forumotion are allowed.

Please google for C++ help forums.

Thread Garbaged.

Male Posts : 48766
Reputation : 2828
Language : English
Location : Mumbai


Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum