Apr 27, 2019 at 8:40pm UTC
My code is almost done but College Board is being a bitch again and requires an abstraction for me to get a good grade but my code is working fine without it and its too late to make a new idea. Help?
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#include <cstdlib>
#include <iostream>
using namespace std;
//the pin is 752634
//can withdraw or deposit only
int bankbalance()
{
int pinNo;
cout << "Please key in your 6 digits PIN number.\n" ;
cin >> pinNo;
int attempts = 3; //total number of tries
int Utries = 1; //counting with respect to the first user input
while (pinNo != 752634 && attempts - Utries != 0)
{
cout << "You have enter an invalid PIN number.\n" ;
cout << "Please try again.\n" ;
Utries++;
cin >> pinNo;
}
if (pinNo != 752634 && attempts - Utries == 0)
{
cout << "You can make no more attempts.\n" ;
cout << "Your account has been locked.\n" ;
cout << "Please re-set your PIN before trying again.\n" ;
}
return pinNo;
}
float amountLeft(float moneytrans)
{
float initialamt;
initialamt = 101876; //amount of money one has in the account
while (initialamt - moneytrans <= 0){
cout << "ERROR\n" ;
cout << "You cannot withdraw that amount.\n" ;
cout << "This is because your savings is less than amount to be withdrawn.\n" ;
cout << "Please input a new amount you wish to withdraw.\n" ;
cin >> moneytrans;
if (initialamt - moneytrans >= 0)
{
cout << "Withdrawal successful!" << endl;
cout << "You have " << initialamt - moneytrans << " in your current account.\n" ;
break ;
}
float finalamt = initialamt - moneytrans;
return finalamt;
}
}
float amtincreased(float deposit)
{
float initialamt;
initialamt = 101876;
float finalamt = initialamt + deposit;
cout << "Deposit successful!\n" ;
cout << "You have " << finalamt << " in your current account.\n" ;
return finalamt;
}
int main()
{
if (bankbalance() == 752634)
{
cout << "You have inputted the correct PIN numbers.\n" ;
}
else
{
return 0;
}
cout << "Please proceed with your transactions.\n" ;
cout << "Please 1 of the following options:\n" ;
cout << "1. Withdrawal\n" ;
cout << "2. Deposit\n" ;
int option;
cin >> option;
if (option == 1)
{
cout << "Please input the amount you wish to withdraw.\n" ;
float amountwith;
cin >> amountwith;
amountLeft(amountwith);
}
else if (option == 2)
{
cout << "Please input the amount you wish to deposit.\n" ;
float deposit;
cin >> deposit;
amtincreased(deposit);
}
return 0;
}
Last edited on Apr 28, 2019 at 12:47am UTC
Apr 28, 2019 at 12:46am UTC
Probably should have specified since it was College Board that made the rules, I'll change my post now
Apr 28, 2019 at 1:42am UTC
And do you know what they mean by "abstraction"? It's a pretty general term... I'm not exactly sure what they want just based off your description.
You could wrap everything in a useless class, and call "bankAccount.process()", which calls the code that is currently in main.