Answer:
Following are the code to the given question:
#include <iostream>//header file
#include <string>//header file
using namespace std;
int main()//main method
{
string region;//defining a string variABLE
while(true)//defining a while loop for input value
{
cout << "Enter the region code(-1 to quit): ";//print message
cin >> region;//input string value
if(region == "-1")//defining if to checks string value
{
break;//use break keyword
}
else//else block
{
if(region.length() != 3)//defining if to check string value length not equal to 3 {
cout<<"Invalid region code. Region code must contain exactly three characters."<<endl;//print message
}
else
{
if(region.at(0) == 'A' || region.at(0) == 'B')//defining at method that checks string value
{
if((region.at(1) >= '0' && region.at(1) <='9') && (region.at(2) >= '0' && region.at(2) <='9'))//defining at method that checks string value
{
if(region.at(0) == 'A')//defining at method that checks string value
{
cout<<"The shipping charge for region is $25."<<endl;//print message
}
else
{
cout<<"The shipping charge for region is $30."<<endl;//print message
}
}
else
{
cout<<"Invalid region code. Region code should start with A or B followed by two numbers."<<endl;//print message
}
}
else
{
cout<<"Invalid region code. Region code should start with A or B."<<endl;//print message
}
}
}
}
return 0;
}
Output:
Please find the attached file.
Explanation:
In this code, inside the main method a string variable "region" is declared that use while loop to the input value and use the conditional statement that checks the input value and print the value as per the condition and print the value.