error c2065 'balance': undeclared indentifier


I receive this error, been couple hours try to understand, but i havent find the solution.

i get the error here:

1
2
3
4
	case 2: 
			
			currentBalance(balance);
			main ();


is it because it doesnt have a value, i serious dont know what my problem.

My whole code.

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
// Lucky ATM.cpp : Defines the entry point for the console application.
//





#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>


using namespace std;
	void main();
	int menu();	
	double currentBalance( double balance);
	double withdraw();
	double deposit ();
	
	float payment();
	int option;
		
	bool unscreen();


void main()
		
{
	
		

	int menu;
	
		cout<<" \n---------------------------------------------------"<<endl;
		cout<<"If you require help, press 1 for unscreen help. \n"<<endl;
		
		cout<<"Please choose from the following option \n"<<endl;
		
		cout<<"Press 2 for to check balance."<<endl;
		cout<<"Press 3 for to make a Withdraw."<<endl;
		cout<<"Press 4 for to make a Deposit."<<endl;
		cout<<"Press 9 to exit"<<endl;
		
					
		cin>>menu;
		

		switch(menu)
		{
		case 1:
			unscreen();
			main ();
		
		
		case 2: 
			
			currentBalance(balance);
			main ();

		case 3:
			withdraw();
			main ();

		
		case 4:
			deposit();
			main ();

		
				
		case 9:
			exit(0);


		default:
			cout<<"You did not choose from the menu options, reloading the menu!"<<endl;
			main();	

		}
	
	
	
}



double currentBalance(double balance)
		{

			double balance = 0;

					
				              
				ifstream readfile;
				readfile.open("renatofile.txt");
				char output [100];
				if (readfile.is_open()) {
					
					while(!readfile.eof()) 
					
					{
						readfile>>output;
					}
				}

				readfile.close();
				balance = atof(output);
				return balance;


}



The compiler is telling you that you are trying to pass a variable called 'balance' into currentBalance on that line, but you haven't ever defined such a variable.

Also, you shouldn't be calling main ever; use a loop if you want to repeat things.
Also, it should be int main(), not void main().

And you don't need to declare main like you have for your other functions. (That is, you don't need line 15.)
how do i defined a variable?

im new to C++, and i thought you defined a value like this
double balance = 0;
Yes, that is a valid way to define a variable. What is the error you are getting?
can you defined a variable like this?

1
2
3
double withdraw( );
	double deposit ( double balance);
	double balance;
the previous error is gone but now i get a another one.

error lnk1120 1 unresolved externals
Yes, that would make it a global variable however. You should probably place it in only the scope where it is needed.

As for your error, please post the new code and the full error message.
im only 14, just learning the language. I read that global variable is bad practice.

I remove the global variable.

and i get the same error as previous.

error c2065 'balance': undeclared indentifier


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

// Lucky ATM.cpp : Defines the entry point for the console application.
//





#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>


using namespace std;
	void main();
	int menu();	
	double currentBalance( double balance);
	double withdraw();
	double deposit ();
	
	float payment();
	int option;
		
	bool unscreen();


void main()
		
{
	
		

	int menu;
	
		cout<<" \n---------------------------------------------------"<<endl;
		cout<<"If you require help, press 1 for unscreen help. \n"<<endl;
		
		cout<<"Please choose from the following option \n"<<endl;
		
		cout<<"Press 2 for to check balance."<<endl;
		cout<<"Press 3 for to make a Withdraw."<<endl;
		cout<<"Press 4 for to make a Deposit."<<endl;
		cout<<"Press 9 to exit"<<endl;
		
					
		cin>>menu;
		

		switch(menu)
		{
		case 1:
			unscreen();
			main ();
		
		
		case 2: 
			
			currentBalance(balance);
			main ();

		case 3:
			withdraw();
			main ();

		
		case 4:
			deposit();
			main ();

		
				
		case 9:
			exit(0);


		default:
			cout<<"You did not choose from the menu options, reloading the menu!"<<endl;
			main();	

		}
	
	
	
}



double currentBalance(double balance)
		{

			double balance = 0;

					
				              
				ifstream readfile;
				readfile.open("renatofile.txt");
				char output [100];
				if (readfile.is_open()) {
					
					while(!readfile.eof()) 
					
					{
						readfile>>output;
					}
				}

				readfile.close();
				balance = atof(output);
				return balance;


}
You still need a balance variable. Since you are only using the function in main, go ahead and put the variable in main somewhere.

Looking at your function though, it doesn't seem like you need (or use) the parameter passed to it anyway. You can probably just remove it.
When i declare the balance variable in the main.

I get this error.

error LNK1120: 1 unresolved externals
error LNK2019: unresolved external symbol "double_cedcl deposit(double" (?deposit@@YANN@Z) referenced in function_main
That error is from the linker saying that it can't find the function double which you declared on line 20, but never defined. You'll need to define it so the linker can find it.
how will i defined, i already did some research but the answer i find dont resolve my problem.
Works now.

Well till now. :)
for you great help and patient with me.
Topic archived. No new replies allowed.