1. ## Else....if statements help and more.

Heya guys new to this great board and programming in general (well I did a little plain english if you can consider that a programming language). I'm also back in college as a freshman at 26 so I think I am having a bit more of a problem getting the swing of it then my younger counterparts because I didn't have this stuff in high school. But I regress...

I am trying to create a mail/weight/cost calculator for introo to c++

I guess its a problem more or less with if...else statements. Heres my code:
Code:
```#include <iostream>
using namespace std;
const double ENVELOPE_POSTAGE = 1;
const double FIRST_PRIORITY_COST = 3.85;
const double SECOND_PRIORITY_COST = 8.40;
const int LOW_RANGE = 1;
const int FIRST_CLASS_MAX = 13;
const int FIRST_PRIORITY_MAX = 159;
const int PRIORITY_MAX = 160;
int main ()
{
int weight;
double cost;
int mailService;

cout<<"What is the weight of the envelope that you would like to send? "<<endl;
cin>>weight;
if (weight > PRIORITY_MAX)
cout<<"You have entered an invalid number"<<endl;
//return 0;
if(weight < LOW_RANGE)
cout<<"Your postage is in the low range and it's envelope postage";
//return 0;
if(weight <= FIRST_CLASS_MAX)
cout<<
cout<<"First Class Mail"<<endl;
cost = .37 + (weight - 1) * .23;
cout<<"You owe "<<cost<<endl;
cout<<endl;
return 0;
if(weight = 160)
cout<<"Priority mail"<<endl;
cost = 8.40;
cout<<"you owe 8.40"<<endl;
return 0;

//cout<<endl;
//if(weight <= FIRST_PRIORITY_MAX)
//cout<<FIRST_PRIORITY_COST<<" and it's Priority";
//cout<<endl;```

the problem is when I try to get it to calculate a statement it also calculate the others....and I don't want that. Anyone take a stab at what I am doing wrong?

2. first of all I would make weight a double instead of an int.
next:

Code:
```if(weight <= FIRST_CLASS_MAX){
cout<< //you should get an error here so delete it
cout<<"First Class Mail"<<endl;
cost = .37 + (weight - 1) * .23;
cout<<"You owe "<<cost<<endl;
cout<<endl;
return 0;
} else if    (weight == 160) {
cout<<"Priority mail"<<endl;
cost = 8.40;
cout<<"you owe 8.40"<<endl;
return 0;
}

//and so on....if your if statement is supposed to do more than
//one thing always put everything in brackets {}, actually I put
//everything in brackets, no matter the length.```
axon
P.S. Next time you post a thread make sure it has a better title/subject....help doesn't cut it

edit::this is the if else technioque i use just for completeness:
Code:
```if( condition ){
//do stuff here
} else if ( condition2 ){
//some more stuff
} else {
//default condition
}```

3. Thanks Axon that helped me out a bunch

4. Since I got you here how would I go about doing an if/and statement. For example if(mail < x) AND (mail > Y)

5. if(mail<x&&mail>y)

6. Code:
```// AND statement
if(mail < x && mail > y)
{
// Code here
}

// OR statement
if(mail < x || mail > y)
{
// Code here
}```
Hope that helps .

Brendan

7. Code:
```if( (mail < x) && (mail > Y) ){
//................
}```
for the program to go into this if statement both conditions must be true.