Please help me with the errors in this code.

I need help with this code. I get the error c4700 uninitiated local variable "balance" used. line 42

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
 #include "MenuBuilder.h"


MenuBuilder::MenuBuilder(void)
{
	balance = 2439.45;
}


MenuBuilder::~MenuBuilder(void)
{
}


void MenuBuilder::buildMenu()
{
	cout << endl;
	cout << "     Welcome to the DeVry Bank Automated Teller Machine" << endl << endl;
	cout << " 1.   Check Balance " << endl;
	cout << " 2.   Make Withdrawl " << endl;
	cout << " 3.   Make Deposit  " << endl;
	cout << " 4.   View Account Information " << endl;
	cout << " 5.   View Statement " << endl;
	cout << " 6.   View Bank Information " << endl;
	cout << " 7.   Exit " << endl;
	cout << "      Enter Selection: " << endl;

}
void MenuBuilder::processInput(int choice)
{
	double withdrawl;
	double deposit;
	double balance;

	switch (choice)
	{
	case 1: cout << " Your current balance is: " << endl; break;
	case 2: cout << " How much would you like to withdraw? " << endl;
		cin >> withdrawl;

		if (balance > withdrawl && withdrawl > 0)
		{balance = balance - withdrawl;
			cout << " Your balance after withdrawl is : "<< balance << endl;  }
		else
			cout << " Invalid withdrawl!" << endl;
		break;
	case 3: cout << " How much would you like to deposit? " << deposit << endl;
		cin >> deposit;
		if (deposit > 0)
		{

			balance = balance + deposit;
			cout << " You balance after deposit is: " << endl;
		}
		else
			cout << " Invalid deposit! " << endl;
		break;
	case 4: cout << " Account information : " << endl;
		cout << " Name: Alicia Shorts" << endl;
		cout << " Account Number: 246743522829" << endl;
		break;
	case 5: cout << " 01/01/11 - McDonald's - $6.27 " << endl;
		cout << " 01/15/11- Kwik Trip - $34.93" << endl;
		cout << " 02/28/11- Target-$124.21" << endl;
		break;
	case 6: cout << " DeVry Bank, established 2011" << endl;
		cout << " (123) 456-7890" << endl;
		cout << " 12345 1st St." << endl;
		cout << " Someplace, NJ 12345" << endl;
		break;
	case 7: cout << "Good-bye" << endl; break;
	default: cout << " Invalid selection" << endl; break;

	}// switch


}


This is the rest of the files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

class MenuBuilder
{
private:
	double balance; // private data member
public:

	MenuBuilder();
	~MenuBuilder();
	// methods
	void buildMenu();
	void processInput(int);
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "MenuBuilder.h"

int main()
{
	// declare variables
	MenuBuilder transaction;
	int choice = 0;
	while (choice != 7)
	{
		transaction.buildMenu();
		cin >> choice;
		transaction.processInput(choice);
	}


	return 0;



}


I get the error c4700 uninitiated local variable "balance" used. line 42

you need to give balance a value before you use it.
Topic archived. No new replies allowed.