In: Computer Science
I NEED TO DEBUG THIS PSUEDOCODE
// This pseudocode should determine and output the rental fees
for cars.
// Standard cars rent for $65 per day, compacts rent for $40 per
day,
// and subcompacts rent for $30 per day. Rentals for at least 7
days
// receive a 20% discount. An error message is displayed if the car
type
// is not valid.
start
Declarations
string carType
num days
num STD_RATE = 65
num COM_RATE = 40
num SUB_RATE = 30
num DAYS_FOR_DISCOUNT = 10
num DISCOUNT_RATE = 0.20
string QUIT = "ZZZZ"
getReady()
while carType <> QUIT
detailLoop()
endwhile
finish()
stop
getReady()
output Enter car type or , QUIT, to quit
input carType
return
detailLoop()
output "Enter days rented "
input days
if carType = "Standard" then
rate = STD_RATE
else
if car_Type = "Compact" then
rate = COMPACT_RATE
else
if carType = "Subcompact" then
rate = SUB_RATE
else
rate = 0
output "Invalid car type"
endif
endif
endif
if rate <> 0
if days >= DAYS_FOR_DISCOUNT then
rate = rate * DISCOUNT_RATE
endif
output carType, days
output "Enter car type or ", QUIT, " to quit "
input carType
return
finish()
output "End of program"
return
Pseudo-code for car rentals:
Start
   string carType;
   num days;
   num rate=0;
   num discount=0;
   num STD_RATE = 65;
   num COM_RATE = 40;
   num SUB_RATE = 30;
   num DAYS_FOR_DISCOUNT = 10;
   num DISCOUNT_RATE = 0.20;
   string QUIT = "ZZZZ";
Call getReady() function and save return value in carType
   While carType is not QUIT Then
       output "Enter days rented "
       input days
       if carType is equal to "Standard"
Then
           Set rate =
STD_RATE;
       else if (carType is equal to
"Compact" Then
           Set rate =
COM_RATE
       else if (carType is equal to
"Subcompact" Then
           Set rate =
SUB_RATE
       Otherwise
           Set rate =
0
           output "Invalid
car type"
       End if
       If rate is not equal to 0
Then
           output "Rental
Fee: $"<<rate<<endl;
           If days >=
DAYS_FOR_DISCOUNT Then
          
    Calculate discount = rate * DISCOUNT_RATE;
          
    output "Discount Fee: $",discount
          
    output "Net fee: $", (rate-discount)
           End if
       End if
       Call getReady() function and
save return value in carType
   End While
  
Stop
getReady()
    string carType;
   output "Enter car type or , QUIT, to quit: ";
   input carType;
return carType;
---------------------------------------------------------------------------------------------------------------------
C++ code of
above pseudo-code :
//main.cpp
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
string getReady();
int main()
{
   string carType;
   int days;
   float rate=0;
   float discount=0;
   int STD_RATE = 65;
   int COM_RATE = 40;
   int SUB_RATE = 30;
   int DAYS_FOR_DISCOUNT = 10;
   float DISCOUNT_RATE = 0.20;
   string QUIT = "ZZZZ";
   carType=getReady();
   //Check if carType is not ZZZZ
   while(carType!=QUIT)
   {
       //read days
       cout<<"Enter days rented
";
       cin>> days;
       //Check if carType is
"Standard"
       if (carType == "Standard" )
           rate =
STD_RATE;
       //Check if carType is
"Compact"
       else if (carType == "Compact"
)
           rate =
COM_RATE;
       //Check if carType is
"Subcompact"
       else if (carType == "Subcompact"
)
           rate =
SUB_RATE;
       else
       {
           //Set
rate=0
           rate = 0;
           //print a
invalid car type message
          
cout<<"Invalid car type"<<endl;
       }
       //Check if rate is not 0
       if (rate != 0)
       {
          
cout<<"Rental Fee: $"<<rate<<endl;
           if (days >=
DAYS_FOR_DISCOUNT )
           {
          
    discount = rate * DISCOUNT_RATE;
          
    cout<<"Discount Fee:
$"<<discount<<endl;
          
    cout<<"Net fee:
$"<<(rate-discount)<<endl;
           }
       }
       carType=getReady();
   }
   system("pause");
   return 0;
}
string getReady()
{
   string carType;
   cout<<"Enter car type or , QUIT, to quit:
";
   cin>>carType;
   return carType;
}
---------------------------------------------------------------------------------------------------------------------
Sample Output:
