Uninitialized Variables???

So I was trying to complete this program but I am having difficulty with a warning I am getting that is saying many of my values in my void definition section are uninitialized. Some examples of these are in lines 97 with variable 'currentLimit' and 110 with variable 'amount'.

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//------------------------------------------------------------------------------
//Program Description
//Create an application for a credit card company that allows
//the user to make a purchase using the credit card, transfer a balance from
//another credit card, calculate the minimum credit card payment
//due and view their available credit line.
//------------------------------------------------------------------------------

#include <iostream>

void getPin(int& pin);
bool isValidPin(int pin);
void getAmount(double& amount);
void makePurchase(double amount, double& currentLimit);
void creditTransfer(double amount, double& creditLimit);
void minPayment(double creditLimit);


int main()
{
    using namespace std;
    int input;

    getPin(input);
    isValidPin(input);

    return 0;
}
void getPin(int& pin)
    {
        using namespace std;
        cout << "Please enter the pin" << endl;
        cin >> pin;
    }
bool isValidPin (int pin)
    {
        using namespace std;
        int input_category;
        double cost, creditMax = 1000;

        if (pin == 1234)
        {
        do
            {


            cout << "1. Pay for purchase" << endl;
            cout << "2. Balance transfer from another credit card" << endl;
            cout << "3. Calculate minimum payment" << endl;
            cout << "4. View available credit limit" << endl;
            cout << "5. Exit" << endl;
            cin >> input_category;

            switch (input_category)
                {
                case 1:
                    getAmount(cost);
                    makePurchase(cost, creditMax);
                    break;

                case 2:
                    getAmount(cost);
                    creditTransfer(cost, creditMax);
                    break;

                case 3:
                    minPayment(creditMax);
                    break;

                case 4:
                    cout << "Your credit limit is $";
                    cout << creditMax << endl;
                    break;

                case 5:
                    cout << "Thank You." << endl;
                    return 0;
                    break;
                }
            }while((input_category > 0) && (input_category <= 5));
                cout << "Incorrect Entry." << endl;
        }
        else
        {
            cout << "Incorrect Pin Entry" << endl;
        }
        return false;
    }
void getAmount(double& amount)
    {
        using namespace std;
        double currentLimit;

        cout << "Please enter the amount " << endl;
        cin >> amount;

        if (amount <= currentLimit)
           {
            cout << "Transaction is successful.";
           }
        else
           {
            cout << "Insufficient Funds." << endl;
           }
    }
void makePurchase(double amout, double& currentLimit)
    {
        using namespace std;
        double creditLimit = 1000.00, amount;
        currentLimit = creditLimit - amount;
        cout << " Your credit limit after transaction is $";
        cout << currentLimit << endl;
    }
void creditTransfer(double amount, double& creditLimit)
    {
        using namespace std;
        double total_charge, currentLimit;
        total_charge = amount + 10.00;
        currentLimit -= total_charge;

        if (total_charge <= currentLimit)
        {
            cout << "Your credit limit after transaction is $";
            cout << currentLimit << endl;
        }
        else
        {
            cout << "Insufficient Funds." << endl;
        }
    }
void minPayment(double creditLimit)
    {
        using namespace std;
        double payMin, currentLimit;
        payMin = (creditLimit - currentLimit) * 0.05;

        cout << "Your minimum payment is $";
        cout << payMin << endl;
        return;
    }

Last edited on
You are using variables which do not have a value. What those mentioned variables equals to on the place of first use? Where did you set that value?
You just have to using using namespace std; once after #include <iostream> instead of placing using namespace std; in every subfunction , your whole program still can be executed without using std:: in your program......

And I dont get any warning by executing your program
The issue I was having was that the variables change depending on what the user input is so I couldn't assign a variable to all of them. The program did not seem to be keeping track of how the variables were changing such as the currentLimit. This is what kept me from assigning the value of zero to the variables that where uninitialized. I didn't want it to attribute zero to that variable when it went to a new function.
On line 97 you are comparing amount to currentLimit. Amount is entered by user on previous line. But what currentLimit is? Where was it set? What it represents? How computer would know about it?

92
93
94
95
96
double currentLimit; //What is value of this variable?
cout << "Please enter the amount " << endl;
 cin >> amount;
if (amount <= currentLimit)
{          // ↑ What are you comparing amount with? 
Last edited on
After I check your code I found that in line 97 you are using the comparision between an initiallize variable with an uninitialize variable..... If you wish to check for the maximum limit available for you should pass your creditMax into your function....
Topic archived. No new replies allowed.