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

Recommended Answers

All 2 Replies

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/

expected primary-expression before "else"

expected `;' before "else"

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.