Thread: menus

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    1
    Rep Power
    0

    Question menus


    what i need to do is when it asks how many transactions to enter, it will keep coming up until it gets to that number.
    then the menu come up. like this.


    void display_menu(void)
    {
    cout << "xxxxxxxxxxxxxxxxxxxxxxx" <<endl;
    cout << "x 1. Deposit x" << endl;
    cout << "x 2. Withdraw x" << endl;
    cout << "x 3. Print Customers x" << endl;
    cout << "x 4. Print Transaction x" << endl;
    cout << "xxxxxxxxxxxxxxxxxxxxxxx" <<endl;
    cin>>cchoice

    This is my Problem on this code: when i type in a number it doesnt execute what i want it to do. are these case statements right? also i dont know that to do for #4

    switch (cchoice)
    {
    case 1:
    cout << "What is you SSSN? ";
    cin << SSN;

    cout << "How much would you like to deposit? ";
    cin << sDeposit;
    break;

    case 2:
    cout << "What is you SSSN? ";
    cin << SSN;
    cout << "How much would you like to withdraw? ";
    cin << sAccount;
    break;

    case 3:
    cout<<setw(20)<<"Account number"
    <<setw(13)<<"Name"
    <<setw(9)<<"Balance" << endl;

    cout<<setw(20)<<"_________________"
    <<setw(13)<<"__________"
    <<setw(9)<<"_______"<<endl;

    cout<<setw(20)<<sName;
    cout<<setw(13)<<AccountNumber
    <<setw(9)<<Balance<<endl;
    break;

    case 4:
    break;

    }
    return 0;
    }

    This is what needs to happen when they type ina number

    1. or 2. Deposit and Withdraw: it will prompt the user for the account # , and amount to enter or withdraw.

    3. Print customers: will show all data( account number, names, balance) printed to screen

    4. Print transaction: will prompt for a account and then print all of the transactions (type, Amount)
    this is the part im stuck on, what to put into the case statements to make 1-4 happen.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,184
    Rep Power
    2222
    Stupid question: Shouldn't the arrows in the input statements point to the right?

    For example, you wrote:
    Code:
    cin << sDeposit;
    Shouldn't it be?:
    Code:
    cin >> sDeposit;
    I've never tried it your way before, so I don't know if it will compile or not. However, that might explain why it's not doing what you expect it to.


    Oops! As you were! I was looking at the cases within the switch statement, not at the menu! You did the cin right in the menu, though you still need to correct it in the different cases.

    What is the data type of cchoice? If it is not an integer type -- the name suggests char to me -- , then you will need to make it one or else convert it properly or else keep it a char and make your cases for character values (eg, case '1': instead of case 1: ).

    As it stands, if cchoice is of type char, then when you enter a '1', its value will be the ASCII value of '1', which is 49. Since none of the switch's cases is for 49, nothing will happen. You should put in a default case (default: ) to trap all other values of cchoice. It should output an error message that includes the value of cchoice received.
    Last edited by dwise1_aol; April 3rd, 2003 at 02:36 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    First of all, it sounds like you're way over your head on this program, so you either haven't been studying or your teacher has been going way too fast for you.

    "What i need to do is when it asks how many transactions to enter, it will keep coming up until it gets to that number"

    You might want to consider a for loop.

    In a switch statement, each case needs brackets around the body of the code. Check the format of a case statement in your book.

    "this is the part im stuck on, what to put into the case statements to make 1-4 happen"

    I would create 4 functions that you call depending on what the user chooses. Think of each function as a miniature program to do what you want. Concentrate on one function, code it, and then test it to make sure it works correctly, then move on to the next function.
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    ^^ what he said except that case's dont need brackets. :)
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Yikes! Sorry about that, I don't know what I was looking at.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    11
    Rep Power
    0
    Have you solve your problem?

IMN logo majestic logo threadwatch logo seochat tools logo