The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

C++ HELP!

3 posters

Go down

C++ HELP! Empty C++ HELP!

Post by magicm00n 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:
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
magicm00n
magicm00n
Active Poster

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

Back to top Go down

C++ HELP! Empty Re: C++ HELP!

Post by LGforum 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.
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

C++ HELP! Empty Re: C++ HELP!

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

Sorry, only questions related to Forumotion are allowed.

Please google for C++ help forums.

Thread Garbaged.
Sanket
Sanket
ForumGuru

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

Back to top Go down

Back to top


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