HELP- Beginner Atm program

I can't get the error messages solved. I followed my pseudocode but can't get rid of the errors can someone help me??

TestMenu.cpp
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 BANK;
	int choice=0;
	while(choice != 7)
	{
		BANK.buildMenu();
		cin >> choice;
		BANK.processInput(choice);
	}


	return 0; 



}


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

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

// deconstructor
MenuBuilder::~MenuBuilder(void)
{
}

// output the menu
void MenuBuilder::buildMenu()
{

	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;

}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
	double withdrawl;
	double deposit;
	double balance;

	switch(choice)
	{
	case 1: cout << " Your current balance is: " << balance << endl; break;
	case 2: cout << " How much would you like to withdraw? " << endl;
		cin >> withdrawl;
		if(balance > withdrawl && withdrawl > 0)
			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 += deposit;
			cout << " You balance after deposit is: " << balance << 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


}


MenuBuilder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#ifndef MenuBuilder
#define MenuBuilder
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

class MenuBuilder
{
private:
	double balance; // private data member
public:
	MenuBuilder(void); // constructor
	~MenuBuilder(void); // deconstructor
	// methods
	void buildMenu();
	void MenuBuilder::buildMenu();
	void processInput(int);
};

#endif 

Any help is greatly appreciated!
Last edited on
What error messages?

Go on, give us a starting point ;-)

Jim
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
1
1>  TestMenu.cpp
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(14): error C2208: 'void' : no members defined using this type
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(15): error C2059: syntax error : '('
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(15): error C2238: unexpected token(s) preceding ';'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(18): error C2039: 'buildMenu' : is not a member of '`global namespace''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(18): error C2535: 'void <unnamed-tag>::buildMenu(void)' : member function already defined or declared
1>          c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(17) : see declaration of '<unnamed-tag>::buildMenu'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(20): warning C4094: untagged 'class' declared no symbols
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\testmenu.cpp(6): error C2065: 'BANK' : undeclared identifier
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\testmenu.cpp(10): error C2065: 'BANK' : undeclared identifier
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\testmenu.cpp(10): error C2228: left of '.buildMenu' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\testmenu.cpp(12): error C2065: 'BANK' : undeclared identifier
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\testmenu.cpp(12): error C2228: left of '.processInput' must have class/struct/union
1>          type is ''unknown-type''
1>  MenuBuilder.cpp
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(14): error C2208: 'void' : no members defined using this type
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(15): error C2059: syntax error : '('
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(15): error C2238: unexpected token(s) preceding ';'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(18): error C2039: 'buildMenu' : is not a member of '`global namespace''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(18): error C2535: 'void <unnamed-tag>::buildMenu(void)' : member function already defined or declared
1>          c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(17) : see declaration of '<unnamed-tag>::buildMenu'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(20): warning C4094: untagged 'class' declared no symbols
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(4): error C2589: '(' : illegal token on right side of '::'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(4): error C2059: syntax error : '::'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(5): error C2143: syntax error : missing ';' before '{'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(5): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(10): error C2611: '(' : illegal following '~' (expected identifier)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(10): error C2062: type 'void' unexpected
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(10): error C2059: syntax error : ')'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(11): error C2143: syntax error : missing ';' before '{'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(11): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(15): error C2039: 'buildMenu' : is not a member of '`global namespace''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(30): error C2039: 'processInput' : is not a member of '`global namespace''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(44): error C2181: illegal else without matching if
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(53): error C2181: illegal else without matching if
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Generally it's a good idea to fix the very first error in the list - most of the others will be caused by that one confusing the compiler on subsequent lines.

So, the 1st error is telling you it doesn't like the 'void' in the constructor definition, menubuilder.h line 14. Try taking it out and see if that works.

Cheers,
Jim
Thanks, that didn't seem to do the trick I need that part of the prototype for the constructor
Did it fix the first compilation error? Now move on to the next one and fix that. It might not be obvious at a quick glance that the error messages have changed, but I think they will have.

Can you repost the error list with the 'void' removed?

You'll also have to remove this line from the MenuBuilder class declaration in menubuilder.h

 
void MenuBuilder::buildMenu();


The class qualifier (before the ::) is only used in the CPP file for the actual body definition of the method. You already have the method prototype declaration on the previous line.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1>  MenuBuilder.cpp
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(16): error C2059: syntax error : '('
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(16): error C2238: unexpected token(s) preceding ';'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.h(20): warning C4094: untagged 'class' declared no symbols
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(4): error C2589: '(' : illegal token on right side of '::'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(4): error C2059: syntax error : '::'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(5): error C2143: syntax error : missing ';' before '{'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(5): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(10): error C2611: '(' : illegal following '~' (expected identifier)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(10): error C2062: type 'void' unexpected
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(10): error C2059: syntax error : ')'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(11): error C2143: syntax error : missing ';' before '{'
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(11): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(15): error C2039: 'buildMenu' : is not a member of '`global namespace''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(30): error C2039: 'processInput' : is not a member of '`global namespace''
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(44): error C2181: illegal else without matching if
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(52): error C2181: illegal else without matching if

1> Generating Code...
I removed that! I did see that error last minute. The error did change somewhat.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#ifndef MenuBuilder
#define MenuBuilder
#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);
};

#endif 

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

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

// deconstructor
MenuBuilder::~MenuBuilder(void)
{
}

// output the menu
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;

}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
	double withdrawl;
	double deposit;
	double balance;

	switch(choice)
	{
	case 1: cout << " Your current balance is: " << balance << 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: " << balance << 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


}

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; 



}
Last edited on
And if you format your code with code tags we can tell the line numbers and be able to read it easier.

1
2
Edit your post, select the code, then press the <> button on the format menu out to the right.


So it looks like this:

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

int main()
{
// declare variables
    MenuBuilder transaction;
    int choice=0;

    while(choice != 7) {
          transaction.buildMenu();
          cin >> choice;
          transaction.processInput(choice);
    }

return 0;
}



You may get more replies if you do this.

Have you tried removing all the void's as parameters? They have never been a requirement for a C++ function with no parameters.

HTH
Last edited on
Thank you. I get another error when I remove the void also.
OK, I just saw what the problem is.
MenuBuilder.h has the following:

 
#define MenuBuilder 


That defines a macro "MenuBuilder" as an empty string. From that point on, wherever "MenuBuilder" appears in your code, it's replaced with an empty string.

The #pragma once line performs the functionality for you anyway, so just remove the #ifndef, #define and related #endif lines.

Jim
1
2
3
4
5
6
7
8
1>  TestMenu.cpp
1>  MenuBuilder.cpp
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(4): error C2761: '{ctor}' : member function redeclaration not allowed
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(5): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(44): error C2181: illegal else without matching if
1>c:\users\610pawn\documents\visual studio 2010\projects\lab6\lab6\menubuilder.cpp(52): error C2181: illegal else without matching if
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Is the new error. smh I feel so stupid to what I'm doing.
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
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
#include "MenuBuilder.h"

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

// deconstructor
MenuBuilder::~MenuBuilder(void)
{
}

// output the menu
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;

}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
	double withdrawl;
	double deposit;
	double balance;

	switch(choice)
	{
	case 1: cout << " Your current balance is: " << balance << 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: " << balance << 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


}


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; 



}
The error says it's on line 4 of MenuBuilder.cpp
Let's have a look:

1
2
3
4
5
6
7
#include "MenuBuilder.h"

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


What do you notice about line 4? What does it have that shouldn't be there? Clue: the error message is saying that member function redeclaration is not allowed. Redeclaration, not definition.

Jim
THANKS! Oh ok it's the ";" in the part. The only thing I keep deleting and retyping is the if else statements says expecting a statement. Is it the matter of spacing or too much information on lines: 44 and 52
NEVERMIND I JUST MADE ANOTHER IF STATEMENT. THANKS EVERYONE FOR ALL THE HELP!!
Last edited on
No worries
Topic archived. No new replies allowed.