943,106 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 296
  • C++ RSS
Feb 8th, 2010
0

tracking looping

Expand Post »
How would i keep track of money spent? and items bought when i loop and how do i say i want multiple items meaning if i want to purchase more than one teeshirt or mug.


  
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
 are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
 cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
 stuff for them.*/

 #include<iostream>
 using namespace std;
 int main()
 {
    char symb;
    int item_purch, numb_item_purch, quit, answ;
    double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;

    cout << "You have 30 dollars to spend.\n";
    do
    {
        cout << endl;
    cout << "What do you want to buy today?\n";
     tot_mon = 30;

            cout << " A) Mugs $2.50 " << endl;
            cout << " B) teeshirt $9.50 " << endl;
            cout << " C) Pens .75 cents " << endl;
            cout << " D) Quit" << endl;
            cout << " Enter your letter and press Return when finished" << endl;
            cin >> symb;

            cout.setf(ios::fixed);
            cout.setf(ios::showpoint);
            cout.precision(2);


     
C++ Syntax (Toggle Plain Text)
  1. switch (symb)
  2. {
  3. case 'A':;
  4. case 'a':;
  5. cout << " You have choosen A) mugs for $2.50 \n" << endl;
  6. mug = 2.50;
  7. curr_cash = tot_mon - mug;
  8. cout << " You have " << curr_cash << " remaining \n " << endl;
  9. tot_mon = 30;
  10.  
  11. break;
  12. case 'B':;
  13. case 'b':;
  14. cout << " You have choosen B) teeshirt for $9.50 " << endl;
  15. teeshirt = 9.50;
  16. curr_cash = tot_mon - teeshirt;
  17. cout << " You have " << curr_cash << " remaining \n " << endl;
  18. tot_mon = 30;
  19. break;
  20.  
  21. case 'C':;
  22. case 'c':;
  23. cout << " You have choosen C) Pens for .75 cents " << endl;
  24. pen = .75;
  25. curr_cash = tot_mon - pen;
  26. cout << " You have " << curr_cash << " remaining \n " << endl;
  27. tot_mon = 30;
  28. break;
  29.  
  30. case 'D':;
  31. case 'd':;
  32. cout << " You have choosen D) which means you want to Quit" << endl;
  33. quit = 0;
  34. break;
  35.  
  36. default:
  37. cout << "Input error. Select again" << endl;
  38. }
  39. if ( curr_cash = 0)
  40. {
  41. cout << "You need more cash, you dont have enough\n" << endl;
  42. curr_cash = tot_mon - mon_spent;
  43. }
  44. else
  45. {
  46. cout << " Would you like anothe purchase, please choose another letter.\n" << endl;
  47.  
  48. }
  49. } while ( curr_cash <= 0);
  50.  
  51. cout << "Thank you for shopping.\n";
return 0; }
Similar Threads
Reputation Points: 3
Solved Threads: 0
Junior Poster
timbomo is offline Offline
122 posts
since Feb 2010
Feb 8th, 2010
-2
Re: tracking looping
C++ Syntax (Toggle Plain Text)
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char symb;
  10.  
  11. double mug = 2.50f,
  12. teeshirt = 9.50f,
  13. pen = 0.75f,
  14. tot_mon = 30.0f;
  15.  
  16.  
  17. cout << "You have 30 dollars to spend.\n";
  18.  
  19. do
  20. {
  21. cout << endl;
  22. cout << "What do you want to buy today?\n";
  23.  
  24. cout << " A) Mugs $2.50 " << endl;
  25. cout << " B) teeshirt $9.50 " << endl;
  26. cout << " C) Pens .75 cents " << endl;
  27. cout << " D) Quit" << endl;
  28. cout << " Enter your letter and press Return when finished" << endl;
  29. cin >> symb;
  30.  
  31. cout.setf(ios::fixed);
  32. cout.setf(ios::showpoint);
  33. cout.precision(2);
  34.  
  35.  
  36.  
  37. switch (symb)
  38. {
  39. case 'A':
  40. case 'a':
  41. cout << " You have choosen A) mugs for $2.50 \n" << endl;
  42. tot_mon -= mug; // minus equal total money
  43. cout << " You have " << tot_mon << " remaining \n " << endl;
  44. break;
  45.  
  46. case 'B':
  47. case 'b':
  48. cout << " You have choosen B) teeshirt for $9.50 " << endl;
  49. tot_mon -= teeshirt;
  50. cout << " You have " << tot_mon << " remaining \n " << endl;
  51. break;
  52.  
  53. case 'C':
  54. case 'c':
  55. cout << " You have choosen C) Pens for .75 cents " << endl;
  56. tot_mon -= pen;
  57. cout << " You have " << tot_mon << " remaining \n " << endl;
  58. break;
  59.  
  60. case 'D':
  61. case 'd':
  62. cout << " You have choosen D) which means you want to Quit" << endl;
  63. tot_mon = 0;
  64. break;
  65.  
  66. default:
  67. cout << "Input error. Select again" << endl;
  68. }
  69. if ( tot_mon == 0.0f ) // == not =
  70. cout << "You need more cash, you dont have enough\n" << endl;
  71. else
  72. cout << " Would you like anothe purchase, please choose another letter.\n" << endl;
  73.  
  74. } while ( tot_mon >= 0.0f ); // Bigger than not smaller than
  75.  
  76. cout << "Thank you for shopping.\n";
  77.  
  78. return NULL;
  79. }

I recomend doing the money check before hand, and if you want to add a Item count then simply multiply the money amount by it.
Reputation Points: 49
Solved Threads: 6
Junior Poster
VilePlecenta is offline Offline
106 posts
since Jan 2010
Feb 8th, 2010
-1
Re: tracking looping
i have never used and i dont believe my teacher wants us to use these

#include <Windows.h> or #include <conio.h>

is there away to create this program using this format

#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit, answ;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
Reputation Points: 3
Solved Threads: 0
Junior Poster
timbomo is offline Offline
122 posts
since Feb 2010
Feb 8th, 2010
0
Re: tracking looping
yes those aren't needed ( you can erase them )
They just got mixed in when I pasted your code into my previous project.
Reputation Points: 49
Solved Threads: 6
Junior Poster
VilePlecenta is offline Offline
106 posts
since Jan 2010
Feb 8th, 2010
0
Re: tracking looping
now these errors r coming up

error: expected `,' or `;' before "tot_mon"|
error: `curr_cash' was not declared in this scope|
error: `curr_cash' was not declared in this scope|
error: `mon_spent' was not declared in this scope|
error: `curr_cash' was not declared in this scope|
Reputation Points: 3
Solved Threads: 0
Junior Poster
timbomo is offline Offline
122 posts
since Feb 2010
Feb 8th, 2010
0
Re: tracking looping
yes i got it. but do you know why i had to do that? i just dont want the answer i want to actually understand why so i wont be lost when i have to do it on a test?
you are very smart and i would like ur help
Reputation Points: 3
Solved Threads: 0
Junior Poster
timbomo is offline Offline
122 posts
since Feb 2010

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: Array passing problem
Next Thread in C++ Forum Timeline: String Selection Sort with files





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


Follow us on Twitter


© 2011 DaniWeb® LLC