Advertisement
userxbw

Monitor sales C++

Sep 19th, 2022 (edited)
1,058
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 1 0
  1. #include <iostream>
  2. //std::setprecision()
  3. #include <iomanip>
  4. // priceme.cp
  5. using std::cout;
  6. using std::cin;
  7. using std::numeric_limits;
  8. using std::streamsize;
  9. using std::setprecision;
  10. void options();
  11. void Quantity();
  12. double get_subtotal(int tm,int tg,int td,
  13.             double mp, double gp,double dp);
  14. void total_sales(double st);
  15. void clear_error();
  16. int main(){
  17.       double
  18.       monitor=159.99,
  19.       getdone=179.99,
  20.       delight=249.99;
  21.       int q=0,option=0,mc=0,mg=0,md=0;
  22.       char run='y';
  23.       while(run=='y'){
  24.             options();
  25.             cin>>option;
  26.                   if(!cin){
  27.                         clear_error();
  28.                         continue;
  29.                   }
  30.             switch(option){
  31.             case 1:
  32.             Quantity();
  33.             cin>>q;
  34.             if(!cin){
  35.                   clear_error();
  36.                   continue;
  37.            }
  38.                   mc+=q;
  39.             break;
  40.             case 2:
  41.             Quantity();
  42.             cin>>q;
  43.             if(!cin){
  44.                   clear_error();
  45.                   continue;
  46.            }
  47.                    mg+=q;
  48.             break;
  49.               case 3:
  50.             Quantity();
  51.             cin>>q;
  52.             if(!cin){
  53.                   clear_error();
  54.                   continue;
  55.            }
  56.                   md+=q;
  57.             break;
  58.             case 4:
  59.             run='n';
  60.             break;
  61.             default:
  62.                   clear_error();
  63.             break;
  64.             } // end switch
  65.       } // end while
  66. total_sales(get_subtotal(mc,mg,md,monitor,getdone,delight));
  67. return 0;
  68. }
  69. double get_subtotal(int tm,int tg,int td,
  70.             double mp, double gp,double dp)
  71. {
  72.       cout<<"\n\n\t\tTOTAL ORDER\n"
  73.       <<tm<<" ICU Monitors @ $"<<(tm*mp)<<"\n"
  74.       <<tg<<" Get'er done mon. @ $"<<(tg*gp)<<"\n"
  75.       <<td<<" Gamer's delight @ $"<<(td*dp)<<"\n"
  76.       <<"\n";
  77. return ((tm*mp)+(tg*gp)+(td*dp));
  78. }
  79. void total_sales(double st)
  80. {
  81.       cout<<"\nTotal Cost of Monitors: $"
  82.       << st
  83.       <<"\nSales Tax (calculated at 6.5%): $"
  84.       <<setprecision(5)
  85.       <<((st*6.5)/100)
  86.       <<"\nBalance Due: $"
  87.       <<(st+(st*0.065))
  88.       <<"\n";
  89. }
  90. void options()
  91. {
  92.       cout<<"\n\n\t\tMENU \n"
  93.       <<"\n1. ICU Monitor $159.99"
  94.       <<"\n2. Get'er Done! Monitor $179.99"
  95.       <<"\n3. Gamer's Delight Monitor $249.99"
  96.       <<"\n4. Checkout"
  97.       <<"\nEnter the option (1-4): ";
  98. }
  99. void Quantity()
  100. {
  101.       cout<<"Enter quantity.\n";
  102. }
  103. void clear_error()
  104. {
  105.        cout<<"\nInvalid option\n" ;
  106.        cin.clear();
  107.        cin.ignore(
  108.        numeric_limits<streamsize>::max(),
  109.        '\n');
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement