Modifying a Program with Functions

I need a little assistance with a program I need to modify. Here is the original code.

#include <iostream>
using namespace std;

int main()
{
double savings = 0, checking = 0, amount;
int choice;
char cont;
do
{
system("cls");
printBalances(checking, savings);
choice = readInput();

switch(choice)
{
case 1:
withdraw(checking);
break;
case 2:
cout <<"How much would you like to deposit? $";
cin>> amount;
checking = deposit(checking, amount);
break;
case 3:
withdraw(savings);
break;
case 4:
cout <<"How much would you like to deposit? $";
cin>> amount;
savings = deposit(savings, amount);
break;
}
printBalances(checking, savings);

cout<<"Another transaction? Enter y for yes or n for no ";
cin>>cont;

}while(cont == 'y' || cont == 'Y');
return 0;
}

****************I have to modify this code using these requirements:

Program: You and I are working together to create a transaction program for a bank. My job is to create the main function that will run the program (which I’ve already done), and you are to create the functions that do all of the work. I have included the code I have written. You are to add your code to the file, and you are not to change or add anything in the body of the main that I’ve written.

Specifications:
1) The user should not be allowed to overdraw either of their accounts.
2) All entered monetary amounts must be non-negative.


I really have no idea where to start. Could anyone suggest where I can get the ball rolling with this one?

It looks like you have some functions that you need to define. These are printBalances, readInput, withdraw and deposit. Think about the parameters and return types that each of these functions will have (their usage in main should give you hints).

From there, you should be able to write the prototypes. Hopefully at that point you'll be able to fill in the logic of each function in accordance with the problem description.

This sounds like a homework question, so I think you'll learn more if you sweat over it for a while. Post up your next attempt when you're really stuck...
Topic archived. No new replies allowed.