Thread: void problem

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

    void problem

    the prorgram runs but it shuts down you chose a product. can somebody look for the error?


    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    void display_menu();
    void tax(float);
    float total = 0;
    
    int main()
    {
    char choice;
    display_menu();
    cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << setprecision(2);
    
    cout << "Welcome to the Rodeo Snack Bar!" << endl;
    cout << "Your current total is: $"<< total << endl;
    cout << "Please enter the letter of your selection: ";
    cin >> choice;
    cout << endl;
    
    switch (choice)
    {
    
    case 'S': case 's':
    cout << "Sandwich - $5.00" << endl;
    total+=5;
    display_menu();
    break;
    case 'C': case 'c':
    cout << "Chips - $1.50" << endl;
    total+=1.5;
    display_menu();
    break;
    case 'P': case 'p':
    cout << "Pickle - $0.75" << endl;
    total+=.75;
    display_menu();
    break;
    case 'B': case 'b':
    cout << "Brownie - $1.00" << endl;
    total+=1;
    display_menu();
    break;
    case 'R': case 'r':
    cout << "Regular Drink - $2.00" << endl;
    total+=2;
    display_menu();
    break;
    case 'L': case 'l':
    cout << "Large Drink - $3.50" << endl;
    total+=3.5;
    display_menu();
    break;
    case 'X' : case 'x':
    cout << "Canceled, please start over." << endl;
    total = 0;
    display_menu();
    break;
    case 'T' : case 't':
    tax(total);
    break;
    default:
    display_menu();
    }
    
    
    }
    
    
    
    
    void display_menu()
    {
    cout << endl;
    cout << "S - Sandwich $5.00" << endl;
    cout << "C - Chips $1.50" << endl;
    cout << "P - Pickle $0.75" << endl;
    cout << "B - Brownie $1.00" << endl;
    cout << "R - Regular Drink $2.00" << endl;
    cout << "L - Large Drink $3.50" << endl;
    cout << "X - Cancel sale and start over" << endl;
    cout << "T - Total the sale" << endl;
    cout << "All items have additional 8.25% tax." << endl;
    }
    
    
    void tax(float total)
    {
    
    cout << "Sub-total: " << total << endl;
    cout << "+ Tax : " << total*0.0825 << endl;
    cout << "Total : " << total + (total*0.0825)<< endl; 
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That's what you tell it to do: you print the menu, get a choice, print the answer, print the menu again, then quit. Did you want something else?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    5
    will in my case it only flashes the interface. when i choose something it automatically closes!!!
    i am using Dev-C++ compiler. i cant do anything with it cause it closes automatically. system pause will not do.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Stop for input at the end of main(). While waiting for input, the console window in which the program output is displayed will be visible. Once main() returns, the console window closes and is therefore invisible.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  3. msvc just ate one of my source files
    By Eber Kain in forum C++ Programming
    Replies: 6
    Last Post: 07-01-2004, 05:40 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM