Closed Thread
Results 1 to 2 of 2

Thread: Need some coding help!!

  1. #1
    Gianmbaio is offline Newbie
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    superjacent is offline Newbie
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0
    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...";
    }

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. coding
    By diya in forum General Programming
    Replies: 5
    Last Post: 11-05-2011, 10:14 AM
  2. Need Help on php coding
    By Mastspace in forum PHP Development
    Replies: 5
    Last Post: 04-21-2010, 05:18 AM
  3. Coding Help
    By Hunter100 in forum JavaScript and CSS
    Replies: 4
    Last Post: 04-03-2010, 04:52 AM
  4. Coding an IRC# Bot, some help please :)
    By SgtPunishment in forum C# Programming
    Replies: 3
    Last Post: 03-27-2010, 10:14 AM

Tags for this Thread

Bookmarks

Posting Permissions

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