Thread: continue yes or no

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    73

    continue yes or no

    I give the prompt at the end to checkout another customer, they have to pick Y or N. If they pick N it will go to the good bye, sotre closing, ect...but if they pick Y then it just sits there, it does not know to go back up top to customer two....how can I change this?

    Bryan

    Code:
    #include <iostream>
    #include <fstream>
    #include <cctype>
    #include <string>
    //#include "grocery.h"
    
    using namespace std;
    
    int ProdNum;
    string ProdName;
    float ProdPrice; 
    char Taxable;
    int Quantity;
    
    const int tax_rate=.075;
    
    int main()
    
    {
    	ifstream OpenFile("inventory.txt");
    	
    	char ch;
    
          while(!OpenFile.eof())
      {
    OpenFile.get(ch);
    	cout << ch;
    	}
    	cout << endl << endl;
    	 
    	cout << "Thanks for shopping at OUR Market." << endl << endl;
    
    {
    	int customer = 1;
    
    	cout << "Enter product number and Quantity for customer " << customer++ << endl;
    	cout << "Enter product code 0 to end purchases." << endl << endl;
    
    do
    {
         cin >> ProdNum;  Quantity;
    	
    } while (ProdNum!=0); 
    
    cout<<"Thanks for shopping, your receipt is printed below" << endl << endl;
    }
    
    {
    cout << "Do you want to checkout another customer? (Y) or (N)" << endl;
    				char more;
    				do
    				{
    				cin >> more;
    				}	while (more != 'N');
    						cout << "Close the store for the night. Bye." << endl;
    				}
    				
    
    
    return 0;
    }

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    I don't remember your other posts very well, and I don't have time to really go over this, but I formatted it so it is readable and highlighted the things that don't make sense at first. Most notably, your brackets that don't do anything important.
    Code:
    #include <iostream>
    #include <fstream>
    #include <cctype>
    #include <string>
    //#include "grocery.h"
    
    using namespace std;
    
    int ProdNum;
    string ProdName;
    float ProdPrice; 
    char Taxable;
    int Quantity;
    
    const int tax_rate=.075;
    
    int main()
    {
        ifstream OpenFile("inventory.txt");
        char ch;
    
        while(!OpenFile.eof())
        {
            OpenFile.get(ch);
            cout << ch;
        }
        cout << endl << endl;
        cout << "Thanks for shopping at OUR Market." << endl << endl;
    
        {
            int customer = 1;
    
            cout << "Enter product number and Quantity for customer " << customer++ << endl;
            cout << "Enter product code 0 to end purchases." << endl << endl;
    
            do
            {
                cin >> ProdNum;      Quantity;
            } while (ProdNum!=0); 
    
            cout<<"Thanks for shopping, your receipt is printed below" << endl << endl;
        }
    
        {
            cout << "Do you want to checkout another customer? (Y) or (N)" << endl;
            char more;
            do
            {
                cin >> more;
            }  while (more != 'N');
            cout << "Close the store for the night. Bye." << endl;
        }
        return 0;
    }

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    well you need a main program while loop, something like this:
    Code:
    bool notDone = true;
    char cont;
    
    while ( notDone ){
         //main program functions and such
         std::cout  <<  "continue?";
         std::cin >> cont;
         if ( cont == 'n' ) {
              std::cout << "exiting....";
              notDone = false;  //this will brake out of the loop
         } else { notDone = true; } //the loop will go again
    }
    there are other ways to go also, like with a break and continue statements, but this seems most sufficient to me.

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    jlou, it looks like its only you and I tonite....well confuted answered some posts also...but now I have to go study for my midterm tomorrow.

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    jlou, these brackets do something. They limitate lifetime of the variables inside. Though, it is somehow useless here because they are insignificant (in size). But it can be sometime useful when you want them to alias thus taking less memory on the stack.

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    The brackets definitely do something, but in this case I don't think they do anything important. It looks more like Bryan is having trouble figuring out how to make the loop do what he wants.

    Bryan, you must figure out what you want to repeat if the user selects 'Y', and then loop around that code. You can put a lot of code inside a do while loop, not just one line, so take all the code that you want to repeat and stick that inside the do while loop where you are reading in the answer to "more".

  7. #7
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    I just said it in the case you didn't see the variabels or didn't take the time to realize the role of the brackets. ^^ Besides, I think the author placed them on purpose.

  8. #8
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    I am still a little loss on when I enter Y it stops...I want to make it say customer 2...I thought it would cause I had the customer++ signs above...when I hit N it exits but Y just sits there, so I know I have a problem with it reading back to the top to add customer 2. Also do I ned to create a struc array so it stores all the prodNum for the customers and then reads the inventory file to get the prices of each product number?

    Bryan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  2. Continue and switch
    By camzio in forum C Programming
    Replies: 10
    Last Post: 10-04-2008, 08:31 AM
  3. switch - continue
    By DavidP in forum C Programming
    Replies: 2
    Last Post: 06-24-2004, 10:09 AM
  4. Press enter to continue... beginner code
    By rox in forum C Programming
    Replies: 17
    Last Post: 12-02-2003, 05:32 PM
  5. continue in while loops
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 03-04-2002, 10:58 PM