Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that displays the appropriate shipping charge based on the regio

ID: 3167985 • Letter: W

Question

Write a 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.

Explanation / Answer

%%%% Matlab code %%%%%%

clc;
clear all;
close all;
format short
temp=1;
while(temp)
a=input('Enter the region code : ','s');
l=length(a);
if ( l ~=3 )
disp('Entered region code is invalid ');
else
  
if ( (a(1) >='A' && a(1) <='Z'))

x=sscanf(a(2:end),'%d');
if (x>=10)
fprintf('The shipping charge of region %c is : $ %d ',a(1),x);
else
disp('Entered region code is invalid ');
end

else
disp('Entered region code is invalid ');
end
  
  
end
temp=input('press Any number to countinue and 0 to end the programme');
end

OUTPUT:

Enter the region code : A11
The shipping charge of region A is : $ 11
press Any number to countinue and 0 to end the programme 2
Enter the region code : B34
The shipping charge of region B is : $ 34
press Any number to countinue and 0 to end the programme 3
Enter the region code : C7
Entered region code is invalid
press Any number to countinue and 0 to end the programme 5
Enter the region code : D2A
Entered region code is invalid
press Any number to countinue and 0 to end the programme 5
Enter the region code : A3N
Entered region code is invalid
press Any number to countinue and 0 to end the programme 4
Enter the region code : C45
The shipping charge of region C is : $ 45
press Any number to countinue and 0 to end the programme 4
Enter the region code : 74TV
Entered region code is invalid
press Any number to countinue and 0 to end the programme 0
>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote