+ Reply to Thread
Results 1 to 2 of 2

Thread: Need some coding help!!

  1. #1
    Newbie Gianmbaio is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    2

    Need some coding help!!

    Hey Guys (and Gals),

    I am currently coding a receipt software. If the user gives bad input I have to make them give good input. They cant leave the program until good input is put. The input is Y/N, anything other than that is a wrong input. I know I have to use a "while" statement for this type of problem, i just dont know how. if you can help me I would highly appreciate it. THANKS!!!


    Code:
    
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    
    {
        float saleAmount;
        const float SALETAX = 0.07;
        float percentTip;
        float tipAmount;
        char input = ' ';
    
             
             
             cout << "Would you like to calculate a receipt? Y/N : ";
             cin >> input;
    
    
             
             switch (toupper(input)) 
           {   
             case 'Y':
             cout << endl << "WELCOME TO HAPPY TREE FRIENDS RESTAURANT " << endl << endl;
        
        
             cout << "Please enter sale amount: $ "; 
             cin >> saleAmount;
        
             cout << "Please enter tip percent: % ";
             cin >> percentTip;
        
             //Receipt
             cout << endl << setw(49) << "Happy Tree Friends Restaurant Customer Receipt " << endl;
        
             cout << endl << setw(43) << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl << endl;
             cout     << setw(38) << "Sale amount.............. " << setprecision(4) << saleAmount << endl;
             cout     << setw(38) << "Tip percent.............. " << percentTip << endl;
             cout     << setw(38) << "Tip amount............... " << percentTip * 100 << endl;
             cout     << setw(38) << "Tax Amount............... " << setprecision(2) << SALETAX << endl;
             cout <<endl << setw(38) << "Total.................... " << saleAmount + tipAmount + SALETAX << endl;
             cout << endl  << setw(43) << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl;
    
             break;
             
             case 'N':
           
             cout << "Thank you anyway. Please revisit the HAPPY TREE FRIENDS RESTAURANT " << endl;
             
             break;
             
           }
            
            
    
    
        
        
        
        ofstream outData;
        outData.open("output.txt");     
        
             outData << endl << setw(49) << "Happy Tree Friends Restaurant Customer Receipt " << endl;
        
             outData << endl << setw(43) << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl << endl;
        
             outData     << setw(38) << "Sale amount.............. " << setprecision(4)<< saleAmount << endl;
             outData     << setw(38) << "Tip percent.............. " << percentTip << endl;
             outData     << setw(38) << "Tip amount............... " << percentTip * 100 << endl;
             outData     << setw(38) << "Tax Amount............... " << SALETAX  << endl;
             outData <<endl << setw(38) << "Total.................... " << saleAmount + tipAmount + SALETAX << endl;
    
             outData << endl  << setw(43) << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl;       
             
    
    
        
        
        system("PAUSE");
        return EXIT_SUCCESS;

  2. #2
    Newbie superjacent is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    11
    Here's a snippet, I'm sure you'll get the idea and build upon it.

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        char keepgoing = 'Y';
        cout << "Do you want to continue <Y>es or <N>o : ";
        cin >> keepgoing;
        while (keepgoing == 'Y' || keepgoing == 'y')
        {
            cout << "\nDo stuff in here.....";
            cout << "\nDo you want to continue <Y>es or <N>o : ";
            cin >> keepgoing;
        }
        cout << "\n\nNow out of loop...";
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. New Anti-Cheat Community needs coding help
    By avguste in forum PHP Forum
    Replies: 8
    Last Post: 04-04-2008, 04:42 PM
  2. Coding and Databasing on a Pocket PC
    By codingnewb in forum General Programming
    Replies: 2
    Last Post: 06-12-2007, 10:18 AM
  3. Coding a stock ticker accessing an asp DB
    By gtg100i in forum General Programming
    Replies: 2
    Last Post: 12-10-2006, 09:33 AM
  4. How long have you been coding php?
    By cpvr in forum PHP Forum
    Replies: 11
    Last Post: 07-11-2006, 12:41 PM
  5. More Coding Methods
    By RobSoftware in forum General Programming
    Replies: 2
    Last Post: 05-30-2006, 04:42 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts