1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
White raven [17]
3 years ago
6

Write a C++ program that displays the appropriate shipping charge based on the region code entered by the user. To be valid, the

region code must contain exactly three characters: a letter (either A or B) followed by two numbers. The shipping charge for region A is $25. The shipping charge for region B is $30. Display an appropriate message if the region code is invalid. Use a sentinel value to end the program. Save and then run the program. Test the program using the following region codes: A11, B34, C7, D2A, A3N, C45, and 74TV.
Computers and Technology
1 answer:
gregori [183]3 years ago
3 0

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.

You might be interested in
Change the function definition for myint so that xyzfunc uses the same memory locations for myint as in the calling program.
sattari [20]

Answer:

b) void xyzfunc (int &myint);

Explanation:

To use the same memory location as the variable in the calling function we have to pass the variable by reference means passing the same address to the function.So to do that we have use & operator which stands for address.

We will do this as following:-

void xyzfunc (int * myint);

Hence the answer is option b.

8 0
4 years ago
Which registry hive is loaded first during windows startup?
xz_007 [3.2K]
If i'm not mistaken it's "boot.ini"
3 0
3 years ago
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
lyudmila [28]

I am not able to open the pdf kindly send the jpg form.

4 0
3 years ago
Read 2 more answers
Write a format operation that builds a string for the float variable amount that
borishaifa [10]

Answer:

8

Explanation:

3 0
3 years ago
When excel imports an access table, the data is placed in a worksheet _____?
ratelena [41]
Book is the answer!!!!!
3 0
4 years ago
Other questions:
  • .How does kinetic energy affect the stopping distance of a vehicle traveling at 30 mph compared to the same vehicle traveling at
    13·1 answer
  • (2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
    5·1 answer
  • A(n) ________ software installation enables you to decide which features you want to install on the hard drive
    10·1 answer
  • EDI stands for__________________ a) Electronic digital interface b) Electronic data interchange c) Enterprise data interface d)
    5·1 answer
  • If you want to copy data from one cel to another cell that is several rows down in a worksheet, which method should you use?
    11·1 answer
  • Who could be involved in the murder of Mr Douglas​
    6·2 answers
  • .Write a program that reads in the length and width of a rectangular yard (in meters) and the length and width of a rectangular
    15·1 answer
  • Deon plans to ride a 15 mile bicycle trail.his if his average is 20 miles per hour
    15·1 answer
  • Write a python program to calculate the average of two numbers​
    8·1 answer
  • The Horse table has the following columns:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!