Sunday, August 2, 2009

C++ program need help?

/***************************************...


* fuwen xu 05/11/07 switch and looping.cpp *


* This program compute the commissions for the real estate company *


* Input:choice,agent_id,rsp,csp,msp,yesno,... *


* Output:nr,nc, nm,mc,trc,tcc, *


************************************** HISTORY ****************************


* Who Date Description *


**************************************...


* Fuwen Xu 05/11/2007 calculate commissions *


**************************************...


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


using namespace std;





#define RCR 0.1 /*residential commission rate*/


#define CCR 0.2 /*commercial commission rate*/


#define MCR 0.15 /*multiunt dwelling commission rate*/





int main()


{


int id, /*five digit number ID*/


price, /*selling pricce*/


nr=0, /*number of residential commissions computed*/


nc=0, /*number of commerical commissions computed*/


nm=0, /*number of multiunit commissions computed*/


yesno; /* program loops when = 1*/


double trc=0.0 , /*total of residential commissions*/


tcc=0.0 , /*total of commerical commissions*/


tmc=0.0 ; /*total of multiunit dwelling commissions*/


char choice, /*choose the what category r, c, m*/


space = ' '; /*space*/





cout %26lt;%26lt; "\n\n\n\n";


cout %26lt;%26lt; "\n***************Fuwen Commission Computer******************\n";


cout %26lt;%26lt; "\nDo you have a commission to compute?(1 = yes, 0 = no)? ";


cin %26gt;%26gt; yesno;


while (yesno == 1)


{


cout %26lt;%26lt; "\nPlease enter the Agent ID: ";


cin %26gt;%26gt; id;


cout %26lt;%26lt; "\nPlease enter the category of property sold";


cout %26lt;%26lt; "\n(R = residential, C = commercial, M = multiunit): ";


cin %26gt;%26gt; choice;


switch(choice)


{


case 'r':


case 'R':


trc-=trc;


cout %26lt;%26lt;"Please enter the selling price: ";


cin %26gt;%26gt; price;


trc += (price*RCR);


nr += 1;


cout %26lt;%26lt;"\n\nThe commission for this sale for Agent "%26lt;%26lt;space%26lt;%26lt;id;


cout %26lt;%26lt;" is: "%26lt;%26lt;setw(2)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;trc;


break;


case 'c':


case 'C':


tcc-=tcc;


cout %26lt;%26lt;"Please enter the selling price: ";


cin %26gt;%26gt; price;


tcc += (price*CCR);


nc+=1;


cout %26lt;%26lt;"\n\nThe commission for this sale for Agent "%26lt;%26lt;space%26lt;%26lt;id;


cout %26lt;%26lt;" is: "%26lt;%26lt;setw(2)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;tcc;


break;


case 'M':


case 'm':


tmc-=tmc;


cout %26lt;%26lt;"Please enter the selling price: ";


cin %26gt;%26gt; price;


tmc += (price*MCR);


nm+=1;


cout %26lt;%26lt;"\n\nThe commission for this sale for Agent "%26lt;%26lt;space%26lt;%26lt;id;


cout %26lt;%26lt;" is: "%26lt;%26lt;setw(2)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;tmc;


break;


default:


cout %26lt;%26lt; "\nAn invalid value was entered.\n";


}


cout %26lt;%26lt; "\n\n";


cout %26lt;%26lt; "\nDo you have another commission to compute?(1 = yes,0 = no)? ";


cin %26gt;%26gt; yesno;


}


trc+=trc;


tcc+=tcc;


tmc+=tmc;


cout %26lt;%26lt; "\n\n********************End of Run Report************************";


cout %26lt;%26lt; "\n\nTotal number of Residential commissions computed = "%26lt;%26lt;nr;


cout %26lt;%26lt; "\nTotal number of Commercial commissions computed = "%26lt;%26lt;nc;


cout %26lt;%26lt; "\nTotal number of Multiunit commissions computed = "%26lt;%26lt;nm;


cout %26lt;%26lt; "\nTotal number of all commissions computed = "%26lt;%26lt;(nr+nc+nm);


cout %26lt;%26lt; "\n\nTotal amount of Redidential commissions computed = "%26lt;%26lt;setw(9)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;tr...


cout %26lt;%26lt; "\nTotal amount of Commercial commissions computed = " %26lt;%26lt;setw(9)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;tcc;


cout %26lt;%26lt; "\nTotal amount of Multiunit commissions computed = "%26lt;%26lt;setw(9)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;tm...


cout %26lt;%26lt; "\n\nTotal amount of all commissions computed = "%26lt;%26lt;" $ "%26lt;%26lt;setw(12)%26lt;%26lt;fixed%26lt;%26lt;setprecision(2)%26lt;%26lt;(tr...


cout %26lt;%26lt; "\n";


return 0;








}

C++ program need help?
Your code doesn't keep an accurate total count of sales. For example, for switch case r/R you have trc-=trc, basically setting trc = 0 EVERY TIME switch case r/R is run. So the count is essentially wiped out all the time and when you're done the count isn't correct.
Reply:BigRez,


who says u to "cut" and "paste".


if u know the answer then


just "select" and"copy" then "paste" to C++.





Sorry i can't anser to question b/c i am C student not C++.
Reply:Well, what's the problem?





(You're better off telling us the problem is than just posting the code. When we see the code, Y!Answers will truncate long lines so we can't just cut and paste it into our compilers.)
Reply:Err, whats your question?


No comments:

Post a Comment