0

this is giving me an error at the line that says
loc = (zip.find("605", 0));
can't tell why?!?

void calcShippingCharge(string zip, int RATE605, int RATE606, int &chg)
{
     //search zip code for proper prefix
     int loc = 0;
     loc = (zip.find("606", 0));
     if (loc >= 0)
     chg = RATE606;
     else if 
     loc = (zip.find("605", 0));
     (loc >= 0);
     chg = RATE605;
     else cout << "Invalid entry, please try again" << endl;
     //end ifs
}    //end of calcShippingCharge function
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by philtron
0

What is the error message?

chg = RATE606;
     else if 
     loc = (zip.find("605", 0));
     (loc >= 0);

else if requires a condition. The proper code would have been

void calcShippingCharge(string zip, int RATE605, int RATE606, int &chg)
{
     //search zip code for proper prefix
     if (zip.find("606", 0) != string::npos)
           chg = RATE606;
     else if (zip.find("605", 0) != string::npos)
          chg = RATE605;
     else
          cout << "Invalid entry, please try again" << endl;

}

You should have a look at http://www.cplusplus.com/reference/string/string/find/

0

expected primary-expression before "else"

expected `;' before "else"

i haven't covered npos yet, but your little snippet totally fixed everything!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.