guys i need some advice over here..

can you guys tell me what's the problem with this coding? it says that Warning W8004 assignment1.cpp 46: 'total' is assigned a value that is never used in function main()

here is the coding

// this program display the price for sending package
// via synergy shipping company
#include<iostream.h>
#include<iomanip>

int main()
{
int weight;
float distance, pricedistance, total;
cout << " insert your weight package in kilogram and distance in kilometer.\n ";
cout << " separated by space ";
cin >> weight>>distance;

if (weight <=1 && distance <=10)
{
cout << "sorry we cannot send this package" << endl;
}
else if (weight >= 2 && distance >= 1000)
{
int pricedistance = 1.10;
total = pricedistance * 2;
cout << "the price is $" << pricedistance<<endl;
}

else if (weight >2 || weight<6 && distance >=1000)
{
int pricedistance = 2.20;
total = pricedistance * 2;
cout << "your price is RM" << pricedistance<<endl;
}

else if (weight>6 || weight <10 && distance>=1000)
{
int pricedistance = 3.70;
total = pricedistance * 2;
cout << "your price is RM" << pricedistance <<endl;
}

else if (weight>10 || weight <20 && distance>=1000)
{
int pricedistance = 4.80;
total = pricedistance * 2;
cout << "your price is RM" << pricedistance << endl;
}
return 0;
}

It warns you because you have a variable that you never use, so it seems to be pointless.
Line 42: You calculate total, but never use it. What is the point of the calculation?

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Nothing is wrong with the program itself, it works perfectly. Try using a different compiler. A hint as well, write your code (in the forums) with the code tags.
Is that really the only warning you got? what compiler are you using?

Regardless, all that warning is telling you is that your are calculating total, and then never using the result for anything.
Warnings are the compilers way of trying to give you helpful feedback about things you're doing that the compiler considers strange. They are not necessarily errors, so the program will compile and run.
okay, thanks for the advise, i'll check it again. well i'am only using jgrasp..
I think you have your if conditions wrong. They don't make sense to me. Can you explain in words what the rules are?

To see the problem, consider that the following weight/distance combinations won't have any price:
weight = 1, distance = 100
weight = 0, distance = 100

Also if weight=50, distance = 100, it will be priced using
1
2
int pricedistance = 2.20;
total = pricedistance * 2;



Topic archived. No new replies allowed.