Functions

I am having quite the difficult time making functions work.
This is kind of a mess I just need to know how I can get it working.

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
#include <iostream>
#include <cmath>
using namespace std;

char choose(char z)
{
cout<<"Please enter your choice:" <<endl<<"(D)eposit"<<endl<<"(W)ithdrawl"<<endl<<"(B)alance"<<endl<<"Q(uit)";
cin>> z;
if(z=='D'){
    int menus(int depo);
    int dep;

        cout<<"deposit"<<endl<<"How much would you like to deposit?";
        cin>>dep;
        double balan=dep+balan;
        return balan;
    }
if(z=='W'){
    int withdraw;
    int x;
    int bal;


    cout<<"withdrawl"<<endl<< "How much would you like to withdrawl?";
    cin>>x;
    double newbal=bal-x;
    return newbal;

}
if(z=='B'){
int display (int bal);
cout<<"Your balance is: "<<"\n";
return z;
}

if(z=='Q'){
    cout<<"quit";
    return 0;

if (z!='D'||z!='W'||z!='B'||z!='Q'){
    cout<<"Invalid Selection."<<endl<<"Please choose again.";
}
}

}



int main(){
    char menu;
    double bal=0;
    char choice;
    do {
        choice= menu();    //call the function to display the menu & return the user's choice

        switch(choice) {
            case 'D': bal = deposit (bal); break;
            case 'W': bal = withdrawl (bal); break;
            case 'B': display (bal); break;
                       }
      }
    while (choice !='Q');
    cout <<"\nThank you!\n Come Again!";


}
Line 10,31: You can't declare a function inside another function (choose)

Line 16,27: You're trying to return a double in a function declared as returning a char.

Line 40: Your if statement is defective. It will always be true. You want &&.

Line 45: You have an extra closing brace.

Line 54. You have no function named menu. You have a char named menu, but you can't call that.

Lines 57-59: You have no functions named deposit, withdrawl or display.












Topic archived. No new replies allowed.