#Bank system

43 messages · Page 1 of 1 (latest)

ornate ginkgo
#

So I tried making some sort of Bank system fetauring: Showing balance, Depositing money, Withdrawing money and Exiting. everything went well so far, I made a function for all these options but when I try to start the programm, I just get the message that there are too many arguments in the function, I tried everything but nothing seemed to help. (btw this is not homeworks I just don't know what tag I could use).

here is the relevant part of the code if you need to see more code to help me tell me and I will send it:

switch(option){
case 1:
showBalance(Balance);
break;
case 2:
Depo(Deposit, Balance);
break;
case 3:
Draw(Withdraw, Balance);
break;
case 4:
Exit();
break;
default:
std::cout << "Not a valid input! ";

}

return 0;

}

void showBalance(double Balance){
std::cout << "your balance is " << Balance << '\n';
}

double Depo(double Balance, double Deposit){
Balance = Balance + Deposit;
std::cout << "Thanks for Depositing, you deposited " << Deposit << " And your new Balance is " << Balance << '\n';

return 0;

}

double Draw(double Balance, double Withdraw){
Balance = Balance - Withdraw;
std::cout << "Thanks for Withdrawing, you Withdrawed " << Withdraw << " And your new Balance is " << Balance << '\n';

return 0;

}

void Exit(){
std::cout << "Thanks for visiting us! ";
}

vast otterBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

jaunty moss
#

please format your code @ornate ginkgo

#

do
```cpp
//code here
```

ornate ginkgo
#

do

switch(option){
        case 1: 
            showBalance(Balance);
            break;
        case 2: 
            Depo(Deposit, Balance);
            break;
        case 3: 
            Draw(Withdraw, Balance);
            break;
        case 4: 
            Exit();
            break;
        default:
            std::cout << "Not a valid input! ";

    }

    return 0;
}

void showBalance(double Balance){
    std::cout << "your balance is " << Balance << '\n';
}

double Depo(double Balance, double Deposit){
    Balance = Balance + Deposit;
    std::cout << "Thanks for Depositing, you deposited " << Deposit << " And your new Balance is " << Balance << '\n';

    return 0;
}

double Draw(double Balance, double Withdraw){
    Balance = Balance - Withdraw;
    std::cout << "Thanks for Withdrawing, you Withdrawed " << Withdraw << " And your new Balance is " << Balance << '\n';

    return 0;
}

void Exit(){
    std::cout << "Thanks for visiting us! ";
} 

ornate ginkgo
jaunty moss
#
switch(option){
        case 1: 
            showBalance(Balance);
            break;
        case 2: 
            Depo(Deposit, Balance);
            break;
        case 3: 
            Draw(Withdraw, Balance);
            break;
        case 4: 
            Exit();
            break;
        default:
            std::cout << "Not a valid input! ";

    }

    return 0;
}

why is this just outside a function?

#

this should be inside main

#

nvm

#

i guess you didnt want to copy main?

#

can you please send the whole error and the line + surrounding code that has the error?

vast otterBOT
#

@ornate ginkgo Has your question been resolved? If so, type !solved :)

ornate ginkgo
#

sure gimme a sec

ornate ginkgo
#
#include <iostream>

double Balance = 0;
double Deposit;
double Withdraw;

void showBalance(double Balance);
double Depo();
double Draw();
void Exit();

int main(){
    int option;
    std::cout << "*********************************\n";
    std::cout << "         Enter your choice       \n";
    std::cout << "*********************************\n";
    std::cout << "Options\n";
    std::cout << " 1. Show Balance\n ";                                            
    std::cout << "2. Deposit Money\n ";
    std::cout << "3. Withdraw Money\n ";
    std::cout << "4. Exit\n ";

    std::cin >> option;

    switch(option){
        case 1: 
            showBalance(Balance);
            break;
        case 2: 
            Depo(Deposit, Balance);
            break;
        case 3: 
            Draw(Withdraw, Balance);
            break;
        case 4: 
            Exit();
            break;
        default:
            std::cout << "Not a valid input! ";

    }

    return 0;
}

void showBalance(double Balance){
    std::cout << "your balance is " << Balance << '\n';
}

double Depo(double Balance, double Deposit){
    Balance = Balance + Deposit;
    std::cout << "Thanks for Depositing, you deposited " << Deposit << " And your new Balance is " << Balance << '\n';
    
    return 0;
}

double Draw(double Balance, double Withdraw){
    Balance = Balance - Withdraw;
    std::cout << "Thanks for Withdrawing, you Withdrawed " << Withdraw << " And your new Balance is " << Balance << '\n';

    return 0;
}

void Exit(){
    std::cout << "Thanks for visiting us! ";
}

#

here my code

#

and the error message

#

bankingacc.cpp:30:17: error: too many arguments to function 'double Depo()'
30 | Depo(Deposit, Balance);
| ^~~~~~~~~~~~~~
bankingacc.cpp:8:8: note: declared here
8 | double Depo();
| ^~~~
bankingacc.cpp:33:17: error: too many arguments to function 'double Draw()'
33 | Draw(Withdraw, Balance);
| ^~~~~~~~~~~~~~~
bankingacc.cpp:9:8: note: declared here
9 | double Draw();
| ^~~~

daring jungle
#

you declared void showBalance(double Balance);
at the top

thorn solstice
#

Yea, basically the problem is your forward declare functions have to have the same return type and the parameters have to be the same

thorn solstice
ornate ginkgo
#

I get you in the parameter part. But I don't really get it with the return function.

ornate ginkgo
#

nvm, I understood smth wrong.

thorn solstice
#

Okay

ornate ginkgo
thorn solstice
#
  • You have global variables that you pass as parameters. The point of global variables is that you can access them from anywhere.
  • The Depo() and Draw() function can be void instead of Double. Especially since you’re not using the return values from these functions in main() function
ornate ginkgo
#

I tried not writing them down in parameters but for some reason it gave me an error. If that is what you mean.

thorn solstice
#

Also, even though global variables can make it easier for you sometimes you should more often than not create variables inside of functions

#

And pass them as arguments when you need to use them in other functions

#

Because the functions you created expect arguments to be passed to them. You should keep them and move the global variables to your main function

ornate ginkgo
#

alr will do

thorn solstice
#

Don’t forget to give them values when you move them to the main function or you might get undefined behavior when you run your code

ornate ginkgo
#

sure

ornate ginkgo
thorn solstice
#
    switch(option){
        case 1: 
            showBalance(Balance);
            break;
        case 2: 
            Depo(Deposit, Balance);
            break;
        case 3: 
            Draw(Withdraw, Balance);
            break;
        case 4: 
            Exit();
            break;
        default:
            std::cout << "Not a valid input! ";

    }

#

When a function has a return type other than void you would normally do this

double val = Depo(Deposit, Balance);
thorn solstice
ornate ginkgo
#

alr makes sense

#

Thank you and have a good day

#

!solved

vast otterBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

thorn solstice
#

Np