Please help O:)

0 Justine Amf · September 9, 2014
Hi everyone! please help me code this. . .
i only know about functions and i've tried coding this but i dont know if statements yet or loops, 
//
Write this program using user-defined function.

Make a program that would do a simple bank account system. The program should contain at least two functions for the two major bank account transactions: deposit and withdrawal. Implement this program in a menu drive like application wherein the user will have the option to choose any transaction listed in the menu.

i would really appreciate the help.

Post a Reply

Replies

Oldest  Newest  Rating
+2 Devon Horton · September 9, 2014
I won't write the code itself, but when you are not aware of a solution immediately it's important to write the basic program in pseudocode first. This will allow you to obtain a better understanding of the logic that must be followed. 

Since it just says use user-defined functions rather than creating classes, we'll do it all in main.


/* 
Start
bool exit = false;
double money = 50.00;
double cashOnHand = 0.0;

Output message to user: "Welcome to BuckysRoom Bank"
while exit is = false{
int answer = 0;
Output message to user: "Would you like to Deposit(1), Withdraw(2), Exit(0)?"
Input answer to 'answer' member
switch(answer){
case 0:{
exit = true;
break;
}
case 2:{
Withdraw();
break;
}
case 1:{
Deposit();
break;
}
default:
break;
}
}
Message "Come again~"

 

I haven't tested this pseudocode, so my logic may be off. Since you don't know how to use if statements I'll try to go over them real quick. An if statement is pretty much a conditional check, to see whether the statement is true or false.
Like if we put 
if( (2+2) > 5 )
cin << "TRUE";
cin<<"CONTINUE";


since 3 is left than 5, this if statement will be false, so it skips the cin << "TRUE" and executes the cin <<"CNTINUE".  
Now if we change the sign around to 
if( (2+2) < 5 )

this would evaluate to true meaning both statements will now be outputted.  I suggest watching Bucky's videos on if statements and switch statements prior to continuing the rest of this. I'll post some psuedocode for the user-defined functions another time, but for now it'll be best for you to understand if statements in full. Sorry for the lousy response. 

Hope it helped at least a bit. 
+1 Alan Johnson · September 13, 2014
#include <iostream>
#include <stdlib.h>

using namespace std;

const int DEPOSIT  = 1;
const int WITHDRAW = 2;
const int QUIT     = 3;

void deposit(double& balance) {
cout << "How much would you like to deposit? ";
double input =0;
cin >> input;

if (input < 0)
cout << "You cannot deposit a negative amount." << endl;
else {
balance += input;
cout << "$" << input << " has been deposited into your account. You now have $" << balance << " available." << endl;
}
}

void withdraw(double& balance) {
cout << "How much would you like to withdraw? ";
double input = 0;
cin >> input;

if (input > balance)
cout << "You cannot withdraw that much, you only have $" << balance << " in your account." << endl;
else {
balance -= input;
cout << "$" << input << " has been withdrawn from your account. You now have $" << balance << " available." << endl;
}
}

int main() {
double balance = 0;

cout << "Welcome to the Bank!" << endl;
cout << "You have $" << balance << " in your account." << endl;

while (true) {
cout << "Choose your action (1=Deposit, 2=Withdraw, 3=Quit): ";
int action = 0;
cin >> action;

switch (action) {
case QUIT:
exit(1);

case WITHDRAW:
withdraw(balance);
break;

case DEPOSIT:
deposit(balance);
break;

default:
cin.clear();
cin.ignore(1000, '\n');
cout << "Invalid input! Try again..." << endl;
}
}

return 0;
}


If you still need it then there you go.
0 Justine Amf · September 10, 2014
thank you so much for your help, i admit that i kinda skipped the basics, which is a dumb thing to do. But thanks really i will follow through your pseudocode. . .
0 Justine Amf · September 18, 2014
:D Wow, thanks!
it really helped me, like a lot. . .
  • 1

C++

130,058 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator