Need Help with loop

This is a discussion on Need Help with loop within the C++ Programming forums, part of the General Programming Boards category; #include<iostream.h> void print_menu(int choice); int main() { cout<<"Rodeo Snack Bar.\n"; int choice; cout<<"Which Items Would You Like?\n"; cout<<"1-Sandwich.\n"; cout<<"2-Chips.\n"; cout<<"3-Brownie.\n"; ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    2

    Angry Need Help with loop

    #include<iostream.h>

    void print_menu(int choice);

    int main()
    {
    cout<<"Rodeo Snack Bar.\n";

    int choice;

    cout<<"Which Items Would You Like?\n";
    cout<<"1-Sandwich.\n";
    cout<<"2-Chips.\n";
    cout<<"3-Brownie.\n";
    cout<<"4-Regular Drink.\n";
    cout<<"5-Large Drink.\n";
    cout<<"6-Cancel This Sale & Start Over.\n";
    cout<<"7-Total This Sale.\n";
    cin >> choice;

    print_menu(int choice);

    switch(int choice)
    {
    case 1:
    cout<<"$2.99";
    break;
    case 2:
    cout<<"$1.50";
    break;
    case 3:
    cout<<"$.75";
    break;
    case 4:
    cout<<"$1.50";
    break;
    case 5:
    cout<<"$2.00";
    break;
    case 6:
    cout<<"Cancel The Sale";
    break;
    case 7:
    cout<<"Total The Sale";
    break;
    }

    return 0;
    void print_menu(int choice)

    Ok, here is my program so far..The thing is, i need it to total the whole sale until the choice 7 is chosen, i have asked my teacher, but he doesn't help much. Any help woul dbe appreciated.

    Thanx

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    double subtotal = 0;
    
    ........
    
    switch(int choice) 
    { 
    case 1: 
    cout<<"$2.99"; 
    subtotal += 2.99;
    break; 
    case 2: 
    cout<<"$1.50";
    subtotal += 1.50;
    
    .........
    Just keep a running total and add to it in your switch statement....

    then at the end of the code you have your total

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 03:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 01:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21