943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2279
  • C++ RSS
Mar 20th, 2005
1

Emergency help, my assignment is due in 24hours

Expand Post »
The Acme Software Company sells its "Adding Tutor" software for $109.Quantity discount are given using the following table:
Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%
Write a program that asks for the number of units sold and calculates the total cost of the purchase including discount. Adjust the totalby the sales tax (use 7.75%). Display the total cost, the discount, the sales tax and adjusted amount due. Display a warning and end the program if the number of units sold isnot greater than 0
I have finish but I couldn't calculate and it not work..Can anyone help me please
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
purplefantasy is offline Offline
3 posts
since Mar 2005
Mar 20th, 2005
1

Re: Emergency help, my assignment is due in 24hours

Quote originally posted by purplefantasy ...
I have finish but I couldn't calculate and it not work
Show us what you've got done so far, so we know what to tell you to correct.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Mar 20th, 2005
0

Re: Emergency help, my assignment is due in 24hours

This is what I got so far. Plese help out. I don't know how to do it. I really need help.
C++ Syntax (Toggle Plain Text)
  1. //PREPROCESSOR DIRECTIVE
  2. # include <iostream> //FOR CIN AND COUT
  3. # include <iomanip>
  4. # include <string>
  5.  
  6. using namespace std;
  7.  
  8. //Main Function
  9.  
  10. int main()
  11.  
  12. {
  13. //Define Variables
  14. int Quantity; // QUANTITY OF ITEMS
  15.  
  16. float Cost; // SALES ITEMS
  17. float Discount; // DISCOUNT MONEY
  18. float TaxRate; // SALE TAXES
  19. float TotalCost; // TOTAL AMOUNT FOR EACH ITEM
  20. float AdjustAmount; // THE AMOUNT DUE
  21.  
  22. //DEFINE CONSTANTS
  23. const double DiscountRate1= 0.00f; //Rate CODES
  24. const double DiscountRate2= 0.20f;
  25. const double DiscountRate3 = 0.30f;
  26. const double DiscountRate4 = 0.40f;
  27. const double DiscountRate5 = 0.50f;
  28.  
  29. cout.setf(ios::fixed);
  30. cout.setf(ios::showpoint);
  31. cout.precision(2);
  32.  
  33. cout << "\n\nThe Acme Software Company"; //PROGRAM TITLE
  34. cout << "\nby Kristen Ngoc, Nguyen"; //PROGRAM AUTHOR
  35.  
  36. //ASK USER FOR THE AMOUNT OF UNITS YOU WANT TO PURCHASE
  37.  
  38. cout << "\n\nPlease enter the units you want to purchase:"; //INPUT DATA FOR UNITS
  39. cin >> Quantity;
  40.  
  41. //TEST IF QUANTITY IS GREATER THAN 0
  42. if (Quantity >= 0)
  43. {
  44. //DETERMINE THE DISCOUNT RATE
  45.  
  46. if (Quantity <10 )
  47. {
  48.  
  49. Cost = Quantity * 109;
  50. Discount = Cost * DiscountRate1;
  51. TotalCost = Cost - Discount;
  52. TaxRate = TotalCost *0.0775f;
  53. AdjustAmount = TotalCost + TaxRate;
  54. }
  55.  
  56. else if (Quantity <20)
  57. {
  58.  
  59. Cost = Quantity * 109;
  60. Discount = Cost * DiscountRate2;
  61. TotalCost = Cost - Discount;
  62. TaxRate = TotalCost *0.0775f;
  63. AdjustAmount = TotalCost + TaxRate;
  64. }
  65. else if (Quantity <50)
  66. {
  67.  
  68. Cost = Quantity * 109;
  69. Discount = Cost * DiscountRate3;
  70. TotalCost = Cost - Discount;
  71. TaxRate = TotalCost *0.0775f;
  72. AdjustAmount = TotalCost + TaxRate;
  73. }
  74. else if (Quantity <100)
  75. {
  76.  
  77. Cost = Quantity * 109;
  78. Discount = Cost * DiscountRate4;
  79. TotalCost = Cost - Discount;
  80. TaxRate = TotalCost *0.0775f;
  81. AdjustAmount = TotalCost + TaxRate;
  82. }
  83. else
  84. {
  85.  
  86. Cost = Quantity * 109;
  87. Discount = Cost * DiscountRate5;
  88. TotalCost = Cost - Discount;
  89. TaxRate = TotalCost *0.0775f;
  90. AdjustAmount = TotalCost + TaxRate;
  91.  
  92. }
  93.  
  94.  
  95.  
  96. //DISPLAY RESULTS
  97.  
  98. cout << fixed << showpoint << setw (20);
  99. cout <<"\nSales Results\n";
  100. cout <<"- - - - - - - - - - \n";
  101. cout <<"\n" << setw(20) << "Cost $" << "Cost" << endl;
  102. cout <<"\n" << setw(20) << "Discount rate " << "DiscountRate" << endl;
  103. cout <<"\n" << setw(20) << "Discount $" << "Discount" << endl;
  104. cout <<"\n" << setw(20) << "Total Cost $" << "TotalCost" << endl;
  105. cout <<"\n" << setw(20) << "Sales Taxes $" << "TaxRate" << endl;
  106. cout <<"\n" << setw(20) << "Adjust Amount $" << "AdjustAmount" << endl;
  107.  
  108. }
  109.  
  110. else
  111.  
  112. cout << "Invalid entry\n";
  113. return 0;
  114. }
Last edited by alc6379; Mar 21st, 2005 at 4:05 pm. Reason: added [code] tags
Reputation Points: 11
Solved Threads: 0
Newbie Poster
purplefantasy is offline Offline
3 posts
since Mar 2005
Mar 20th, 2005
0

Re: Emergency help, my assignment is due in 24hours

In all cases remove quotes around bolded section
cout <<"\n" << setw(20) << "Adjust Amount $" << "AdjustAmount" << endl;
Declare DiscountRate in your application and set its value inside each conditional
C++ Syntax (Toggle Plain Text)
  1. cout <<"\n" << setw(20) << "Discount rate " << DiscountRate << endl;

As you've gotten it 95% right, I will post a modified version of this app that you can use as a reference. Don't use it as your assignment or your instructor may get you to explain why you did it that way.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Mar 20th, 2005
0

Re: Emergency help, my assignment is due in 24hours

Can you help me make it look right. Because When I did it. It not show the calculation at all. So I think that's not right so we have to use switch or something. Thanks for you help. It due today. It hard when it run.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
purplefantasy is offline Offline
3 posts
since Mar 2005
Mar 20th, 2005
0

Re: Emergency help, my assignment is due in 24hours

Ok as promised here is my modification based on your algorithym
C++ Syntax (Toggle Plain Text)
  1. # include <iostream>
  2. # include <iomanip>
  3. # include <string>
  4. using namespace std;
  5. int main()
  6. {
  7. int Quantity, Disc;
  8. double Cost, Discount, SalesTax;
  9. cout.setf(ios::fixed);
  10. cout.setf(ios::showpoint);
  11. cout.precision(2);
  12. cout << "\n\nThe Acme Software Company\nby Kristen Ngoc, Nguyen"; //PROGRAM AUTHOR
  13. do
  14. {
  15. cout << "\n\nPlease enter the units you want to purchase: "; //INPUT DATA FOR UNITS
  16. cin >> Quantity;
  17. if (Quantity == 0)
  18. break;
  19. Cost = 109.0 * Quantity;
  20. if (Quantity < 10)
  21. Disc = 0;
  22. else
  23. if (Quantity < 20)
  24. Disc = 20;
  25. else
  26. if (Quantity < 50)
  27. Disc = 30;
  28. else
  29. if (Quantity < 100)
  30. Disc = 40;
  31. else
  32. Disc = 50;
  33.  
  34. cout << fixed << showpoint << setw (20);
  35. cout <<"\nSales Results\n";
  36. cout <<"- - - - - - - - - - \n";
  37. cout << setw(20) << "Cost" << setw(25) << Cost << endl;
  38. Discount = Cost * (double (Disc) / 100.0);
  39. cout << setw(20) << "Less" << setw(25) << Discount << " " << Disc << "%" << endl;
  40. cout << setw(20) << "Total Cost" << setw (25) << Cost - Discount << endl;
  41. SalesTax = (Cost - Discount) * .0775;
  42. cout << setw(20) << "7.75% Sales Tax" << setw (25) << SalesTax << endl;
  43. cout << setw (45) << "_________________" << endl;
  44. cout << setw(20) << "Total" << setw (25) << Cost - Discount + SalesTax << endl;
  45. } while (1);
  46. return 0;
  47. }
Basically all I did with your code is eliminate redundancy. Only have conditionals do what they need to rather than duplicate the same code over and over again.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Mar 21st, 2005
0

Re: Emergency help, my assignment is due in 24hours

Please don't label your thread as Urgent-- it implies that your problem is more important than others. Help is given here on a first-come, first-served basis.

http://www.catb.org/~esr/faqs/smart-...ns.html#urgent
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Detecting garbage inputs
Next Thread in C++ Forum Timeline: Debugging string function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC