Sunday, July 26, 2009

I need a c++ program for this. Can someone help me out?

After many years of being frustrated by a checkbook that wont balance, I decied to write a program to help balance my money market checking account. The program should begin by asking for the month's opening account balance. It should should display a menu that lists the following choices:D for deposit, C for check, W for withdrawl, %26amp; Q for quit. If D is selected, enter the amount of the deposit, %26amp; add the amount to the account balance. If C is entered, get amount of the check, subtractg the check amount from the balance. If W is entered, get amount of withdrawl, subtract amount from the balance. If Q is entered, program should display opening balance, amount deposited, amount withdrawn, amount of checks, and final balance. If something other than D,C, Q, or W is entered, program should issue an error message and redisplay the menu. Allow the user to enter uppercase or lowercase letters.


This is not my HOMEWORK!! This one of our chapter review problems. I do need extra help!!

I need a c++ program for this. Can someone help me out?
Not really a problem requiring C++ ... but ok ... I'll give you a skeleton :





#include %26lt;ctype.h%26gt;


#include %26lt;stdio.h%26gt;








void main()


{


// Note : I am opting for long values rather than floats


// because we are dealing with money. Generally floating


// point error isn't acceptible when dealing with currency.


// But this will complicate input/ouput routines slightly.


// If you want to use floats ... it'll simplify IO procedures but will


// introduce floating point error ... your choice.





long current_balance = 0;


long opening_balance = 0;


long amount_deposited = 0;


long amount_withdrawn = 0;


long amount_checks = 0;





char input;





printf("Entering opening balance : ");


// Get opening balance.


// Set opening_balance to the amount.


// Set current_balance to the amount.








do


{


displayMenu();





printf("Enter selection : ");





// Get selection and convert lower-case to upper-case to ease


// the burden of checking multiple values.


input = toupper(getchar());





// I can't recall if getchar() waits until ENTER is pressed before


// evaluating. If it does, you'll need to add a while loop here to


// remove the potential excess and the newline character(s).


// Some systems use both a line feed and carriage return


// character ... others just use carriage return. You'll have to


// determine based on the system being implemented upon.





switch (input)


{


case 'C' :


printf("Enter amount of check : ");


// Get check amount.


// Add the amount of the check to amount_check.


// Decrement the amount of the check from current_balance.


break;





case 'D' :


printf("Enter amount deposited : ");


// Get amount deposited.


// Add amount to amount_deposited.


// Add amount to current_balance.


break;





case 'Q' :


// Display opening_balance.


// Display amount_deposited.


// Display amount_withdrawn.


// Display amount_checks.


// Display current_balance.


break;





case 'W' :


printf("Enter amount withdrawn : ");


// Get amount withdrawn.


// Add amount to amount_withdrawn.


// Subtract amount from current_balance.


break;





default :


printf("\nError. Invalid selection.\n");


}





} while (input != 'Q');








}








void displayMenu()


{


printf("\n");


printf("=========================\n");


printf("Menu :\n");


printf("=========================\n");


printf("(C) : Check\n");


printf("(D) : Deposit\n");


printf("(Q) : Quit\n");


printf("(W) : Withdrawal\n")


printf("=========================\n");


}








I wish this thing didn't screw up my perfect indentation style :P





Have fun!
Reply:Even if it's not your homework assignment, you will learn a lot more by figuring out how to do it yourself. Here are a few hints:





- Break it down into small procedures.


- Code each one separately and test if it works.


- Start by writing pseudo-code or a list of steps that need to happen in order to complete the procedure.





For example, write a program that will do a "W" operation. Then worry about writing a program that will respond properly to a "W" command (and no other keystroke). Then join the two together. You will also need a member variable for the balance, which gets updated each time a command is executed. Good luck!
Reply:Check out http://www.pscode.com for great examples.
Reply:I've been programming for a while. I personally do not like C++. I would go with C# .Net. All of that is easy to do. C# and C++ are very similar. But they do have their differences. For the part... it's just the syntax that drives me nuts. So... if you have the time. Go for Microsoft's Visual Studios .Net C#. It's powerful and not very hard to learn. If you already know C++, it's really pretty easy.








For the coding part, I would suggest breaking it down and figuring out exactly what you want to do. Declare the variables and on paper sketch out what you want to happen. When you have done this, create the user interface and then insert the code. Doing it this way help keep your code from getting very messy and confusing. Trust me... you don't want messy coding.








Also, remember the variables you create. Don't assign then random names. Use names that make sense.


No comments:

Post a Comment