what does this mean

I just tried to compile my program and the only error I got was that it said line 98: function definition does not declare parameters. I am using g++ to compile
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
#include <iostream>
using namespace std;
        
class CheckingAccount  
{ 
public: 
        //constructors
        CheckingAccount(string name, double bal);
        
        CheckingAccount();
        
        void input();   
        
        //accessors
        double get_balance();
        string get_name();
        void make_deposit();
        void make_withdrawl();
                     
private:
        //account holder's full name
        string full_name;
                        
        //account holder's account balance
        double balance;
};
        
int main
{
        char choice;
        CheckingAccount account = new CheckingAccount;

        account.input();
        
        do{
                cout << "What would you like to do today?" << endl;
                     << "A- Display the account information" << endl;
                     << "B- Make a deposit" << endl;
                     << "C-Make a withdrawl" << endl;
                     << "D-Exit the program" << endl;
                cin >> choice;

                switch(choice){
                        case 'A':
                                cout << "Your name is " << account.get_name() << endl;
                                cout << "You have $" << account.get_balance() << " in your account" << endl;
                        break;
                        case 'B':
                                account.make_deposit();
                        break;
                        case 'C':
                                account.make_withdrawl();
                        break;
                        case 'D':
                                cout << "Exit Checking Account" << endl;
                        break;
                        default:
                                cout << "Not a valid choice" << endl;
                        break;
                }
        }while(choice != 'D');
        return 0;
}
                                
                        
CheckingAccount::CheckingAccount(string name, double bal)
{
        full_name = name;
        balance = bal;
}
                        
CheckingAccount::CheckingAccount()
{
        full_name = "";
        balance = 0.0;
}
                        
void CheckingAccount::input()
{
        cout << "Enter your full name: ";
        cin >> full_name;
        cout << "Enter your account balance: ";
        cin >> balance;
}                       

double CheckingAccount::get_balance()
{
        return balance;
}
                        
string CheckingAccount::get_name()
{
        return full_name;
}
 
void CheckingAccount::make_deposit()
{
        double deposit;
        cout << "How much do you want to deposit? $";
        cin >> deposit;  
        balance = balance + deposit;
}
                        
void CheckingAccount::make_withdrawl()
{
        double withdrawl;
        cout << "How much do you want to withdrawl? $";
        cin >> withdrawl;
        if(withdrawl > balance)
        {
                cout << "You do not have enough money in your account for the withdrawl";
        }else{
                balance = balance - withdrawl;
        }//end if
}

line 98 in my program is line 28 on here
functions need a parameter list (parenthesis)

main is a function. Therefore it should have them:

1
2
3
4
int main() // <- give it parenthesis
{
  //...
}
oh wow thanks duh! except now I am stuck in an infinite loop! any idea why?
Where is the infinite loop?
it is occuring with the string in the CheckingAccount::input()
I can enter without spaces but when I uses spaces for the name it sends it into an infinite loop
I don't see any loop at all in the input() method. If you run it in a debugger and step through the code, how is it looping in input()?
no its not looping in the input. Its looping through the main but it only loops through the main like that when the input is a string with spaces
The problem likely resides in the fact that cin>> will terminate when it hits a whitespace character or newline. Since you entered several spaces, cin>> hits the first one, exits and goes to the next cin>>, which immediately (before you can type any response) reads the space and exits as well. This probably repeats several times. I can't really see why it would loop forever at your while, however. Is "choice" getting assigned a space character or is it staying as uninitialized garbage?
its getting a letter A, B, C, or D. and if I don't use cin>> for the string what can I use?
You should probably use getline(cin, my_string_name);.
That will read until an enter, and won't leave any extra newlines in the buffer either. The only thing is when you read that char with cin>>, it will leave a newline in the buffer that you'll have to toss or ignore.
thanks!
Topic archived. No new replies allowed.