6 Replies - 1686 Views - Last Post: 22 September 2013 - 05:09 PM Rate Topic: -----

#1 Cyan Yoshi   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 20-September 13

C++ cash register problem

Posted 20 September 2013 - 07:12 PM

I just started coding a couple weeks ago and I am stuck on this part of my project. I can not figure out how to make my program have a sentinel control loop so that the user can enter Y for yes to continue to enter their groceries which are in the form of numbers such as 101-110. I need them to be able to enter their groceries until they get to their personal desired amount. Thank you very much in advance, and after hours this is what I have of my code so far.

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath> 
using namespace std;

int main(int argc, char *argv[])
{
    
    int productID = 0;
    char anothersale = 'x';
    double price = 0.0;
    double subtotal = 0.0;
    double salestax = 0.0;
    double total = 0.0;
    double cashdrawer = 500.00;
    
    cout << "Welcome to C++ General Store! Please enter your purchase or type -1 to quit: ";
    cin >> productID;

    
    
    
    switch (productID)
          {
           case 101:
                cout << "The Price is $65.00" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;  
           case 102:
                cout << "The Price is $12.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 103:
                cout << "The Price is $24.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 104:
                cout << "The Price is $38.75" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;
           case 105:
                cout << "The Price is $17.80" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 106:
                cout << "The Price is $16.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 107:
                cout << "The Price is $42.85" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;
           case 108:
                cout << "The Price is $32.99" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 109:
                cout << "The Price is $28.75" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 110:
                cout << "The Price is $51.55" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;  
           default:
                cout << "Our apologies we no longer carry that item." << endl;          
           }          
          
         
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

This post has been edited by jimblumberg: 20 September 2013 - 07:15 PM
Reason for edit:: Added missing code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: C++ cash register problem

#2 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: C++ cash register problem

Posted 20 September 2013 - 09:17 PM

Hi, you print -1 to quit. Is -1 not the sentinel? You want a loop around the code you wish to repeat a while loop should work.
Was This Post Helpful? 0
  • +
  • -

#3 Cyan Yoshi   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 20-September 13

Re: C++ cash register problem

Posted 21 September 2013 - 11:44 PM

View Post#define, on 20 September 2013 - 09:17 PM, said:

Hi, you print -1 to quit. Is -1 not the sentinel? You want a loop around the code you wish to repeat a while loop should work.



Thank you very much I just needed some confirmation and a push in the right direction I think I have it now thanks!
Was This Post Helpful? 1
  • +
  • -

#4 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: C++ cash register problem

Posted 22 September 2013 - 12:06 AM

Hi, very good.

You have this in every case of the switch you could probably just print it after the switch.

                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  


Was This Post Helpful? 0
  • +
  • -

#5 Cyan Yoshi   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 20-September 13

Re: C++ cash register problem

Posted 22 September 2013 - 09:47 AM

Ok so I got this to loop but I cannot figure out how to exit the loop. When I go to enter -1 to leave the loop it sees the default statement instead and prints out the "we no longer carry that message" I cannot remove the default statement otherwise it does not compile. Also I do not know how to make the Yes and No input for the user to work either.




#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath> 
using namespace std;

int main(int argc, char *argv[])
{
    
    int productID = 0;
    char anothersale = 'x';
    double price = 0.0;
    double subtotal = 0.0;
    double salestax = 0.0;
    double total = 0.0;
    double cashdrawer = 500.00;
   
    
   
    cout << "Welcome to C++ General Store! Please enter your purchase or type -1 to quit: ";
    do
    {
    cin >> productID;  
    
    switch (productID)
          {
           case 101:
                cout << "The Price is $65.00" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;  
           case 102:
                cout << "The Price is $12.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 103:
                cout << "The Price is $24.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 104:
                cout << "The Price is $38.75" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;
           case 105:
                cout << "The Price is $17.80" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 106:
                cout << "The Price is $16.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 107:
                cout << "The Price is $42.85" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;
           case 108:
                cout << "The Price is $32.99" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 109:
                cout << "The Price is $28.75" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 110:
                cout << "The Price is $51.55" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;  
           default:
                cout << "Our apologies we no longer carry that item." << endl; 
                break;
                              }          
      }  while        
              ((productID <= 110) && (productID >= 101) && (productID !=-1));
              ((productID !='Y') && (productID !='N') && (productID !='y')&&(productID !='n'));
              
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

This post has been edited by jimblumberg: 22 September 2013 - 01:49 PM
Reason for edit:: Added Missing Code Tags. LEARN TO USE THEM!

Was This Post Helpful? 0
  • +
  • -

#6 Cyan Yoshi   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 20-September 13

Re: C++ cash register problem

Posted 22 September 2013 - 12:29 PM

Well I actually figured that all out on my own the last problem that I have to do is figure out how to give this a running total of whatever the user inputs plus sales tax of 7.5%. I am just not sure where to add that stuff and what exactly to do for it. This is what I have so far I also have another part of where the y and n work just not included in this code.
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath> 
using namespace std;

int main(int argc, char *argv[])
{
    
    int productID = 0;
    char anothersale = 'x';
    double price = 0.0;
    double subtotal = 0.0;
    double salestax = 0.0;
    double total = 0.0;
    double cashdrawer = 500.00;
    
    
   
    cout << "Welcome to C++ General Store! Please enter your purchase or type -1 to quit and calculate totals: ";
    do
    {
         if ((productID < 101) && (productID > 110))
             {
                       cout << "Sorry we are sold out" << endl;
             }         
    cin >> productID;  
    
    switch (productID)
          {               
           case 101:
                cout << "The Price is $65.00 " << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl; 
                break;  
           case 102:
                cout << "The Price is $12.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 103:
                cout << "The Price is $24.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 104:
                cout << "The Price is $38.75" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;
           case 105:
                cout << "The Price is $17.80" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 106:
                cout << "The Price is $16.50" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 107:
                cout << "The Price is $42.85" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;
           case 108:
                cout << "The Price is $32.99" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;          
           case 109:
                cout << "The Price is $28.75" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;     
           case 110:
                cout << "The Price is $51.55" << endl;
                cout << "Would you like to do another sale? Y for Yes and N for No: " << endl;  
                break;  
          }          
      }  while (productID != -1);       
              
              
              
              
              
    
    system("PAUSE");
    return EXIT_SUCCESS;
}



Was This Post Helpful? 0
  • +
  • -

#7 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: C++ cash register problem

Posted 22 September 2013 - 05:09 PM

You can always calculate the sales tax, even on a total of several products.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1