C++ HELP!
3 posters
Page 1 of 1
C++ HELP!
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:
What am I doing wrong?? I am new to c++! help pls
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- Active Poster
- Posts : 1305
Reputation : 217
Language : English
Location : The support forum of Forumotion
Re: C++ HELP!
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.
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- Hyperactive
- Posts : 2265
Reputation : 264
Language : English
Location : UK
Re: C++ HELP!
Sorry, only questions related to Forumotion are allowed.
Please google for C++ help forums.
Thread Garbaged.
Please google for C++ help forums.
Thread Garbaged.
Sanket- ForumGuru
- Posts : 48766
Reputation : 2830
Language : English
Location : Mumbai
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum