I am new to ctt programming and I am having some problems trying to get an understanding of what this programming is all about.

The following program is the code. Note that in the program we must include the requirement that the program end if the user inputs an invalid property code. I have been asked to Re-write this program by replacing switch statement by if statements. Then make a screenshot of the program output on my computer. Here's the program:

// prob04-3. cpp

// This program determines the commission on real estate sales
// depending on the type of property sold.

#include <iostream>
#include <iomanip>
#include <cstd1ib>

using namespace std;

int main ()
{
  const double       RESIDENTIAL_RATE + 0.060;
  const double       MULTIDWELLING_RATE = 0.050;
  cont double         COMMERCIAL_RATE = 0.045;

int          property_code;
double    sale_price,
             commission_rate,
             commission;

cout << setprecision (2)
       << setiosflags (ios::fixed)
       << setiosflags (ios::showpoint) ;
cout << "Enter the property's selling price: ";
cin >> sale price;

cout << end1 ;
cout << "Enter the property code according to the following."
       << end1 << end1 ;
cout << "Residental,            enter R" << end1;
cout << "Multiple Dwelling,   enter M" << end1;
cout Commercial,                enter C" << end1 << end1;
cout << "Please make your selection:  :;

cin. get () ;                 // Discard the \n
property_code = cin.get () ;

switch (property_code)
{
    case 'R' :
    case 'r' :
        commission_rate = RESIDENTAL_RATE;
        break;
    case 'M' :
    case 'm' : 
        commission_rate = COMMERCIAL_RATE;
        break;
     default:
         cout << end1 << end1
                <<"Invalid Property Code! Try Again" << end1;
         edit (1) ;
         break
}
    commission = sale_price * commission_rate;

    cout << end1 << end1;
    cout << "The commsiion is " << commission << end1;

    return 0;
}

Program Output: Enter the property's selling price: 270000

Enter the property's code according to the following:
Residental, enter R
Multiple Dwelling enter M
Commercial, enter C

Please make your selection R

The commission is 16200.00

So, what is the question? To replace the switch statement with a set of if statements

if( property_code == 'R' || property_code == 'r')
{

}
else if( property_code == ???
etc. etc.

Yes that's the question.

The question is:

Re-write program prb04-3.cpp by replacing switch statement by if statements.

Well, just do as I illustrated. We aren't going to do it for you.

I was not looking for anyone to do it. I just needed some help.

I gave you the help you needed. Did you figure it out yet?

I did not figure it out, but I tried the best of my ability. I just started programming and I am trying to learn.

Post what you have tried.

I started right where it asks to replace switch statement by if statements.

if (property_code) case R and commission rate
{
    case 'R' :
    case 'r' :
        commission_rate = RESIDENTAL_RATE;
        break;

The requirement was to REPLACE the case statements with if statements. Let me post a little bit better code snippet. All you have to do with the below code is to add the remaining if statements just as I did for 'R' and 'M'

if( property_code == 'R' || property_code == 'r')
{
    commission_rate = RESIDENTAL_RATE;

}
else if( property_code == 'M' || property_code == 'm')
{
     commission_rate = COMMERCIAL_RATE;
}
else ...

Thanks for your help. I have already been graded for the assignment. Not good at all. I placed the if statements in the wrong place. I would love to see the correct posting for this program. Hopefully I can bounce back next week some how. It will only be my second week, with 11 more to do.

Thanks!

// This program determines the commission on real estate sales
// depending on the type of property sold.

#include <iostream>
#include <iomanip>
#include <cstd1ib>

using namespace std;

int main ()
{
  const double       RESIDENTIAL_RATE + 0.060;
  const double       MULTIDWELLING_RATE = 0.050;
  cont double         COMMERCIAL_RATE = 0.045;

int          property_code;
double    sale_price,
             commission_rate,
             commission;

cout << setprecision (2)
       << setiosflags (ios::fixed)
       << setiosflags (ios::showpoint) ;
cout << "Enter the property's selling price: ";
cin >> sale price;

cout << end1 ;
cout << "Enter the property code according to the following."
       << end1 << end1 ;
cout << "Residental,            enter R" << end1;
cout << "Multiple Dwelling,   enter M" << end1;
cout Commercial,                enter C" << end1 << end1;
cout << "Please make your selection:  :;

cin. get () ;                 // Discard the \n
property_code = cin.get () ;
//ALL YOU HAD TO DO IS REPLACE THE SWITCH STATEMENT
// LIKE I DID BELOW.
//////////////////////////////////////////////////////////////////
    if( property_code == 'R' || property_code == 'r')
    {
       commission_rate = RESIDENTAL_RATE;
    }
    else if( property_code == 'M' || property_code == 'm')
    {
        commission_rate = COMMERCIAL_RATE;

    }
    else
    {
         cout << end1 << end1
                <<"Invalid Property Code! Try Again" << end1;
         exit(1);
    }
////////////////////////////////////////////////////////////////////

    commission = sale_price * commission_rate;

    cout << end1 << end1;
    cout << "The commsiion is " << commission << end1;

    return 0;
}

You made it sound very easy. Remember that was my first time ever trying to do a program. I think I am going to get some tutoring before mid-term comes up in about 6 weeks.

Thanks for your help Ancient Dragon. Hopefully we can still try to solve some ctt problems together. I received this website from my used book that I bought on campus. I will be glad to share this web site with someone who knows a lot more about programming than I do. I don't want to waste your time fooling with a rookie.

Thanks again for trying to help me.

>>You made it sound very easy. Remember that was my first time ever trying to do a program.

you said you wanted to see the final program, so I posted it, knowing that this was your first time. I remember mine too -- I was terrible at it. Keep practicing and you'll get the hang of it.

Thanks for the encouragement!

Have a good night.

I am just wondering why I have keyed this problem in exactly like you have it, it still says I have errors. I joined to try to learn more about how to do these problems. I have all ready submitted my assignment but cannot for the life of me find out how you can run this.

I didn't attempt to compile it, so you may be right about that. There are a lot of other problems with that code, but fixing them was not the object of this thread.

There are a few problems but one of the biggest ones that should get rid of most of the errors is that you wrote end1 but it should really be endl i didn't even notice until i tried to compile it. endl as in the letter L stands for end line. You should be able to fix the rest of your code from the errors you get as they are only small things like quotes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.