Solved

I have to write an algorithm to calculate an architect`s fee.

Posted on 2008-10-28
8
387 Views
Last Modified: 2013-12-14
I have to write an algorithm to calculate an architect`s fee. The fee is calculated as a percentage of the cost of a building. The fee is made up as follows: 8% of the first 5000.00$ of the cost of a building and 3% on the remainder if the remainder is less than or equal to 80000.00 or 2 1/2 %  on the remainder if the remainder is more than 80000.00$. The algorithm will accept the cost of a building and calculate and display the architect`s fee. Test the program with the following costs of buildings: 1000000$
800000$
50000$
35000$
0
Comment
Question by:redscarf
8 Comments
 
LVL 5

Accepted Solution

by:
zmo earned 250 total points
ID: 22824953
Hum.... this looks like a school work.

I shouldn't do that, but as easy as it is, I found it funny to do... it remember me my first year of university, when we were asked stupid questions.

but you have to know, if you ask others to do your homework for you, you won't get far.
int calculate_fee(int cost) {

    int result;

    if (cost <= 5000)

        throw new NotInterestingGetAnotherArchitectError();

//      or simply 'return 8*cost/100;'
 

    // 8% of the first 5000.00$ of the cost of a building

    result = 8*5000/100;
 

    // remainder

    cost = cost - 5000;
 

    // 3% on the remainder if the remainder is less than or equal to 80000.00

    if (cost <= 80000) {

        result = result + 3*cost/100;

    else // or 2 1/2 %  on the remainder if the remainder is more than 80000.00$.

        result = result + 2.5*cost/100;

    return result;

}
 

int main () {

    ...

    calculate_fee(...)

    ...

}

Open in new window

0
 

Assisted Solution

by:KoBeC
KoBeC earned 250 total points
ID: 22825101
I agree, this looks like an assignment! I am going to give you the code though, but try to redo it yourself. It's really easy:

double architectFee(double cost)
{
      cost-=5000;
      if (cost<0)
            return 0;
      else if (cost>80000)
            return 5000*0.08 + cost*0.025;
      else return 5000*0.08 + cost*0.03;
}

This function does it. Like I said, try to do it yourself, it is simple.
0
 
LVL 5

Expert Comment

by:zmo
ID: 22825450
hehe like one say, timtoady
0
 

Author Comment

by:redscarf
ID: 22825538
first of all i thank you for the code, second let me explain:: we have been given abou 20 problems ( the one above is the second of the list) and no one has explained us neither the if,else statement or the switch, when we ask we are given WRONG solutions that make us going crazy for days. So we never know what is right and what is wrong. I borrowed 2 C++ books but are not really usefull. Have You got any suggestion? If You know the title of a good C++ book please let me know as i am in Deep S.....Thank You again.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 16

Expert Comment

by:sh0e
ID: 22826028
http://www.cprogramming.com/tutorial.html#c++tutorial
http://www.cplusplus.com/doc/tutorial/

You'll learn faster by doing.  When you have time and are more advanced, go get a normal programming book.
0
 
LVL 5

Expert Comment

by:zmo
ID: 22826959
so I follow sh0e for his links, and I advice you to begin with

The C language, by Kernighan & Ritchie to learn all the basics of C (and that class of languages)
read also a good book on algorithmics (but I know none in English, sorry) and object oriented programming.

Once you've read all of that, The C++ Language by Bjarne Stroustrup is the next step to go. It's very hard to read, but once you've understood the main ideas of it, you'll be able to switch to any language without a problem (Java, Python, Ruby, whatever...).
0
 

Author Comment

by:redscarf
ID: 22827016
Thanks  to both of You again and duble thanks for having understood  my situation and for the good suggestions about books and tutorials.
0
 

Author Closing Comment

by:redscarf
ID: 31510882
Thank You !
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now