Please help me! Coding Errors.

I have worked on this code.. and now I have TWO seemingly minor errors that I can not figure out. I am new and I would GREATLY appreciate any help you can give me.

Here are my errors:

Error 1: error C2059: syntax error : '}' on Line 63, Column 1.
Error 2: IntelliSense: expected a declaration Line 141, Column 3.

Here is my 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
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
143
// Library
#ifndef MENU_BUILDER_H
#define MENU_BUILDER_H
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
//Define my class
class MenuBuilder
{
double amount;
private:// Private - DO NOT EDIT
string accountNumber;
string firstName;
string middleName;
string lastName;
double withdrwal;
double deposit;
double balance;
public:
MenuBuilder();
MenuBuilder(string accountNumber, string firstName, string middleName, string lastName, 
double withdrwal, double deposit);
void checkBalance();
void withdrawal();
void tdeposit();
void viewAccount();
void viewStatement();
void viewBankInformation();
~MenuBuilder(void);
};
MenuBuilder::MenuBuilder(void)
{
amount=2439.45;
}
MenuBuilder::~MenuBuilder(void)
{
}
void MenuBuilder::checkBalance()
{
cout<<endl<<"Current balance is: $"<<amount;
}
void MenuBuilder::withdrawal()
{
    double amt;
    cout<<endl<<"How much would you like to withdraw? $ ";
    cin>>amt;
    amount=amount-amt;
    do{
        if (amt<0 || amt>balance)
            {
                cout << "That is an invalid amount." << endl;
                break;
             } 
                          else 
                          {
                              amount = (amount-amt);    
                              cout << "Thank you, your new balance is $" << amount << "." << endl; 
                              break;
                          }
    }
}
void MenuBuilder::tdeposit()
{
    double amt;
        cout<<endl<<"How much would you like to deposit? $ ";
        cin>>amt;
            if(deposit > 0)
                  {
                      amount = (amount+amt);    
                      cout << "Thank you, your new balance is $" << amount << ".";
                  }
                  break;
}
void MenuBuilder::viewAccount()
    {
        cout<<endl<<"Name: (Phil Sutton)";
        cout<<endl<<"Account Number: 123456789 ";
    }
void MenuBuilder::viewStatement()
    {
        cout<<endl<<"01/01/11 - McDonalds - $6.27";
        cout<<endl<<"01/15/11 - Kwik Trip - $34.93";
        cout<<endl<<"02/28/11 - Target - $124.21";
    }
void MenuBuilder::viewBankInformation()
    {
        cout<<endl<<"Devry Bank, established 2011";
        cout<<endl<<" (123) 456-7890 ";
        cout<<endl<<"12345 1st St.";
        cout<<endl<<"Someplace, NJ 12345";
    }
int main()//Main menu
    {
        char choice;
        MenuBuilder atm;
            cout<<endl<<"Welcome to the Devry Bank Automated Teller Machine";
        do
            {
                cout<<endl<<endl<<"1. Check balance";
                cout<<endl<<"2. Make withdrawal";
                cout<<endl<<"3. Make deposit";
                cout<<endl<<"4. View account information";
                cout<<endl<<"5. View statement";
                cout<<endl<<"6. View bank information";
                cout<<endl<<"7. Exit";
                cout<<endl<<"Enter your choice: ";
                    cin>>choice;
                        switch (choice)// Case List
                            {
                                case '1':
                                atm.checkBalance();
                                break;
                                case '2':
                                atm.withdrawal();
                                break;
                                case '3':
                                atm.tdeposit();
                                break;
                                case '4':
                                atm.viewAccount();
                                break;
                                case '5':
                                atm.viewStatement();
                                break;
                                case '6':
                                atm.viewBankInformation();
                                break;
                                case '7':
                                cout<<endl<<"Exit the program"<<endl;
                                system("pause");
                                return 0;
                                default:
                                cout<<endl<<"Invalid choice.";
                        }
    }while(true);
        system("pause");
        return 0;
        #endif;
  }



Please help me if you can, this is making my rookie eyes cross!
closed account (3qX21hU5)
Error 1:	error C2059: syntax error : '}'	on Line 63, Column 1.


you are missing your while condition on line 62. For every do-while loop you need a while condition.


As for the other one I will let you figure that one out ;p. Though I will suggest two things. Please please keep your opening and closing brackets on the same lines it makes it much easier to figure out which bracket belongs to the other bracket.

Also do not put your whole program into a header file.
There is no "while" for your do while function.
There is no such a statement as do in C++. There is do-while statement. So this code

1
2
3
4
5
6
7
8
9
10
11
12
13
    do{
        if (amt<0 || amt>balance)
            {
                cout << "That is an invalid amount." << endl;
                break;
             } 
                          else 
                          {
                              amount = (amount-amt);    
                              cout << "Thank you, your new balance is $" << amount << "." << endl; 
                              break;
                          }
    }



is invalid.
Thanks everyone. I am still learning this subject so I'll do my best to implement your advice! Seems as if this code may need a lot of work.
Last edited on
Here is a new take... I am getting closer but clearly I still have a lot of issues. Here is my desired output:

Welcome to the DeVry Bank Automated Teller Machine

1. Check balance
2. Make withdrawal
3. Make deposit
4. View account information
5. View statement
6. View bank information
7. Exit


The result of choosing #1 will be the following:
Current balance is: $2439.45

The result of choosing #2 will be the following:
How much would you like to withdraw? $200.50

The result of choosing #3 will be the following:
How much would you like to deposit? $177.32

The result of choosing #4 will be the following:
Name: (Student’s first and last name goes here)
Account Number: 1234554321

The result of choosing #5 will be the following:
01/01/11 - McDonald’s - $6.27
01/15/11 - Kwik Trip - $34.93
02/28/11 - Target - $124.21

The result of choosing #6 will be the following:
Devry Bank, established 2011
(123) 456-7890
12345 1st St.
Someplace, NJ 12345

The result of choosing #7 will be the following:
*Exit the program - terminate console application.


And here is my current 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
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;


int menu_func(void);

int main(void) {
        int menu = 0;
        double balance;
        double withdraw = 0;
        double deposit = 0;

        while(menu!=7) {

                menu=menu_func();

                switch(menu) {
     case 1:
                  srand(time(0));
                  balance = rand();
          cout << "Your balance is $" << balance << "." << endl;

                  //I don't know how to get it to go back to pick a number on the menu.
     case 2:
                  do
                  {
                          cout << "How much would you like to withdraw?";
                          cin >> withdraw;
                          if (withdraw<0 || withdraw>balance)
                          {
                                  cout << "That is an invalid amount." << endl;
                          }
                          else
                                  cout << "Thank you, your new balance is $" <<balance - withdraw << ".";
                  }
                  while (withdraw<0 || withdraw>balance);
                  break;
     case 3:
          cout << "How much would you like to deposit?";
                  cin >> deposit;
                  if(deposit > 0)
                  {
                          cout << "Thank you, your new balance is $" << balance+ deposit << ".";
                  }
                  break;
     case 4:
          cout << "Name: Beatriz Shimizu";
                  cout << "Account Number: 1234554321";
                  break;
     case 5:
          cout << "01/01/11 - McDonald's\t\t $6.27" << endl;
                  cout << "01/15/11 - Kwik Trip\t\t $11.11" << endl;
                  cout << "02/02/11 - Target\t\t $2.17" << endl;
                  cout << "02/07/11 - In-N-Out\t\t $8.26" << endl;
                  cout << "02/22/11 - DeVry University\t\t $5,233.00" << endl;
                  break;
         case 6:
                  cout << "DeVry Bank, established 2011" << endl;
                  cout << "(123) 456-7890" << endl;
                  cout << "1234 Takeyourmoney Street" << endl;
                  cout << "Someplace, CA 12345" << endl;
                  break;
         case 7:
                  cout << "Thank you for using DeVry Bank Automated Teller Machine.";
                  break;
     default:
          cout << "Invalid Selection";
                  break;
     };
        }

        cout << endl;
        system("pause");
        return 0;
}

int menu_func(void) {
        int menu=0;

        cout << "Welcome to the DeVry Bank Automated Teller Machine" << endl
                 << "1. Check balance" << endl
                 << "2. Make withdrawal" << endl
                 << "3. Make deposit" << endl
                 << "4. View account information" << endl
                 << "5. View statement" << endl
                 << "6. View bank information" << endl
                 << "7. Exit" << endl;
        cout << "Please enter a selection: ";
        cin >> menu;
        return menu;
}


Can anyone point me in the right direction?
Usually when at least one iteration of a loop has to be done it is better to use the do-while loop. So I would substitute your while statement

while(menu!=7) {


for

do
{
//...
} while ( menu != 7 );
Also it would be better if function menu_func would check the correctness of the input.
Yikes, I am so confused.
Topic archived. No new replies allowed.