I am trying to create a program that displays shipping charges for two region codes. The region code has to have exactly 3 characters (the letter A or B followed by two numbers). Display a message if invalid region code is entered. use a sentinel value to exit program. shipping for region A is $25 and region B is $30

Here is what I have so far.
<code>
#include <iostream>
#include <string>
using namespace std;

int main()
{
string regionCode = "";

cout << "Please enter region code (-1 to exit): ";
getline(cin, regionCode);

while (regionCode != "-1")

if (regionCode.find('A', 0))
{
cout << "Shipping cost is $25" << endl;
}

else if (regionCode.find('B', 0));
{
cout << "Shipping cost is $30" << endl;
}
else if
{
cout << "Please enter a valid region code" << endl;
} //end if

cout << "Please enter region code (-1 to exit): ";
getline(cin, regionCode);

system("PAUSE");
return 0;
} //end of main function
</code>

so, have you compiled and run it?

does it do the job?

It won't compile because it's saying the second "else if" isn't valid. I have tried changing things around and the best I can get is when I enter a value starting with"A" it returns nothing and a value starting with "B" returns and endless loop of $25, but it should be $30 and then wait for the user to enter a key to exit

It looks like there are a few issues with your code. Let's go through them step by step.

1. The syntax and placement of your while loop is incorrect. The while loop should enclose all the code that needs to be repeated until the sentinel value ("-1") is entered. In your code, only the first if statement is inside the while loop.

2. The use of `find` function is not appropriate for checking if the region code starts with 'A' or 'B'. The `find` function returns the position of the first occurrence of the specified character, which is not what we need in this case. Instead, we can use string comparison using the `==` operator.

3. The conditions in your if and else if statements are missing checks for invalid region codes. We need to add additional conditions to check the length and format of the region code.

4. There is an unnecessary semicolon after the else if statement for region B. This will cause the subsequent block of code to be executed even if the condition is not met.

Here is the modified code:

```cpp
#include <iostream>
#include <string>
using namespace std;

int main()
{
string regionCode = "";

cout << "Please enter region code (-1 to exit): ";
getline(cin, regionCode);

while (regionCode != "-1")
{
if (regionCode.length() == 3 && (regionCode[0] == 'A' || regionCode[0] == 'B') && isdigit(regionCode[1]) && isdigit(regionCode[2]))
{
if (regionCode[0] == 'A')
{
cout << "Shipping cost is $25" << endl;
}
else if (regionCode[0] == 'B')
{
cout << "Shipping cost is $30" << endl;
}
}
else
{
cout << "Please enter a valid region code" << endl;
}

cout << "Please enter region code (-1 to exit): ";
getline(cin, regionCode);
}

return 0;
}
```

In this modified code, we have added additional conditions to check if the length of the region code is 3, if the first character is 'A' or 'B', and if the second and third characters are digits. If any of these conditions are not met, the program will display the "Please enter a valid region code" message.

It is good practice to include header files `<iosstream>` and `<string>` for input/output and string manipulation respectively. Also, the line `system("PAUSE")` is not necessary and can be removed.

I hope this helps! Let me know if you have any further questions.