Correct variables?

This is just the beginning of my program. This is all new to me, as you can probably tell below, but I'm just checking to make sure I'm on the right path. I welcome any and all advice! Thank you!




//This is an exercise to calculate the cost of shipping a package with "X"
//weight in kg a distance "Y"
#include <iostream>
namespace std;

int main()
{
int weight of package //Weight of package variable
int distance travelled //Distance travelled variable
int envelope //Package weight x <= 2
int small //Package weight 2 < x >= 6
int medium //Package weight 6 < x >= 10
int large //Package weight 10 < x >= 20

{
//Get the weight of the package
cout << "Enter the weight of the package: ";
cin >> weight of package;
}

//If the weight of the package is less than 2 kg
if (weight of package <= envelope)

{
cout << "Enter the distance in miles: ";
cin >> distance travelled;
}
else
{
Last edited on
int weight of package //Weight of package variable

Every word separated by a space in C++ is a whole new token. Try

int weight_of_package; //Weight of package variable

Note also the semi-colon on the end of that statement.

1
2
3
4
int envelope	 //Package weight x <= 2
int small	 //Package weight 2 < x >= 6
int medium	 //Package weight 6 < x >= 10
int large	 //Package weight 10 < x >= 20 


Don't forget to actually give these integers values.
Last edited on
Thanks Moschops. C++ logic is one thing, but applying that to the program language is slow-going!
Do the underscores only apply to variable identifiers? Also, at which point do I enter the price value associated to each package weight---can I assign an integer value ($) to each package weight (kg) variable in the int main() -- that in turn is to be calculated by an integer (distance travelled)
Last edited on
Do the underscores only apply to variable identifiers?


I think you missed the point; there's nothing special about underscores in the middle of variable names. The point is that a variable name can only be a single word.

Also, at which point do I enter the price value associated to each package weight


Whenever you want, so long as the variable has been created.
Last edited on
Topic archived. No new replies allowed.