problem with a program

Module Three Program


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) You are only supposed to add four functions: printBalances, readInput, withdraw, deposit

printBalances
Precondition: take in two double values (account balances) as parameters
Postcondition: print the value of the two parameters.
(Assume the first is the checking account balance and the second is the savings account balance)

readInput
Precondition: prints menu choices and prompts the user to enter number of menu choice
Postcondition: returns valid menu choice

withdraw
Precondition: take in a double (account balance) as a parameter and Prompt the user to enter a withdrawal amount
Postcondition: update the account balance so that the change is reflected outside of the function

deposit
Precondition: take in two double values (account balance and deposit amount) as parameters. Update account balance.
Postcondition: return updated account balance

Error Cheking:
1) The user should not be allowed to overdraw either of their accounts.
2) All entered monetary amounts must be non-negative.
#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;
}

whoah, are you guys in a same class or something? http://www.cplusplus.com/forum/beginner/39548/ :D
whoa hi charles! LMAO wtf?
closed account (zb0S216C)
What are you asking here? Are you confused? Are you struggling with method definitions?
There's no point in posting your assignment and expecting us to know what you want help with. You need to tell us.
Moreover, have you made a genuine attempt at this assignment? By the looks of it, you haven't even bothered.

This is my understanding of your assignment: Basically, your tutor has asked you to define and declare 4 methods.
The details specify what the arguments for each method should be and what the method should do. Finally, you
shouldn't modify the main( ) loop.


Last edited on
Charles, I am in your class. I haven't been able to make it compile yet, but the algorithm is basically ok. Just working out errors with syntax and such. I posted what I have so far in the the thread I have going on this. Don't copy verbatim. It doesn't work yet, but that ought to give you some idea of what you are up against.

ETA..you are supposed to build these AROUND the main. Don't mess with Mr. B's main. Preconditions/declarations at the top.

function calls at the bottom. all outside the curly braces. no need for system("pause") or anything like that- he already did all that. Just write the functions. Hope that helps.
Last edited on
closed account (zb0S216C)
function calls at the bottom.

Do you mean function definitions at the bottom? A function call is different.

In addition to Shannon's post, here's a rough outline of what your code should look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>

using std::cout;
using std::endl;

void printBalances( ... );
void readinput( ... );
void withdraw( ... );
void deposit( ... );

// NOTE: Where 'void' is your desired return type, and, where '...' are your method arguments( if any ).

int main( )
{
    // Main entry-point code...
}

void printBalances( ... )
{
    //...
}

void readinput( ... )
{
    //...
}

void withdraw( ... )
{
    //...
}

void deposit( ... )
{
    //...
}
yes function definitions, sorry. And thanks for outlining the code. I already turned mine in, but hesitated to post the whole thing here...verbatim code is a big no no.

Charles, go to my thread if you want the unfinished version.
Topic archived. No new replies allowed.