How can I implement an abstraction into this code? 2.0

Asking this question again since I didn't get any responses. I need to input an abstraction in this code but it really doesn't need it and its too late to change it. How can I implement one?

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;
}
What do you mean by "no responses"?
I think I see some in: http://www.cplusplus.com/forum/beginner/252867/
It didn't work well srry
It didn't work well
Sad about that. But without a clear specification all effort is grope in the dark (could not find a better translation for "to stir with a rod throug the fog").
The only "abstraction" I might see is not really an abstraction. Your program is currently for one account only, this and that is hardwired in the code. How about making it more universal, fast re-usable, same task different customer.
This would be a generalization, not an abstraction.
Write your program using a class. Have class called Bank and have functions inside the class that modify balances and functions that print data.

https://www.tutorialspoint.com/cplusplus/cpp_data_abstraction.htm
Topic archived. No new replies allowed.