Thread: program not solving

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    Question program not solving

    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <conio.h>
    
    using namespace std;
    
    void display_menu();
    void tax(float);
    
    float total = 0, cash=0;
    
    int main() {
        char choice;
        bool more = true;
        cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << setprecision(2);
    
        while(more) { //loop until the user wants more
            cout << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
            cout << "Welcome to Jimmy's Snack Bar!" << endl;
            display_menu();
            cout << "Please enter the letter of your selection: ";
            cin >> choice;
            switch (choice) {
            case 'S':
            case 's':
                cout << "Sandwich - P30.00" << endl;
                total+=30;
                break;
            case 'C':
            case 'c':
                cout << "Chips - P50.00" << endl;
                total+=50;
                break;
            case 'P':
            case 'p':
                cout << "Pansit - P20.00" << endl;
                total+=20;
                break;
            case 'H':
            case 'h':
                cout << "Hotdog - P25.00" << endl;
                total+=25;
                break;
            case 'D':
            case 'd':
                cout << "Coke - P15.00" << endl;
                total+=15;
                display_menu();
                break;
            case 'B':
            case 'b':
                cout << "Burger - P25.00" << endl;
                total+=25;
                break;
            case 'X' :
            case 'x':
                cout << "Canceled, please start over." << endl;
                total = 0;
                break;
            case 'T' :
            case 't':
                tax(total);
                cout<<"how much do you want to pay."<<endl;
                cin>>cash;
                cout << "Total : " << cash-(total + (total*0.12)) << endl;
                more = false; //stop the loop
                
                //_____________
    
                
                
                break;
            default:
                cout << "Ooops! something went wrong.. :(\n\n";
                return 0; //end the program
            }
            cout << "Your current total is: P "<< total << "\n\n";
            
        
        }
        return 0;
    }
    
    
    
    
    void display_menu() {
        cout << endl;
        cout << "S - Sandwich P30.00" << endl;
        cout << "C - Chips P50.00" << endl;
        cout << "P - Pansit P20.00" << endl;
        cout << "H - Hotdog P25.00" << endl;
        cout << "D - Coke P15.00" << endl;
        cout << "B - Burger P25.00" << endl;
        cout << "X - Cancel sale and start over" << endl;
        cout << "T - Total the sale" << endl;
        cout << "All items have additional 12% tax." << endl;
    }
    
    
    void tax(float total) {
        cout << endl;
        cout << "Sub-total: " << total << endl;
        cout << "+ Tax : " << total*0.12 << endl;
        cout << "Total : " << total + (total*0.12) << endl;   
        cout << "Total : " << cash-(total + (total*0.12)) << endl;//problem is this one
        
       
        
    
    
        
    }


    i need help in this program. i was asking the user to input the cash. the program SHOULD THEN solve with the equation. but the program end up just asking the price and not solving at all.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    try to add

    Code:
    cin.ignore();
    after
    Code:
    cin >> choice;
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM