Banking system program

+2 Glen Chamisa · November 27, 2015
I'm making a C program in visual studio that offers the user 5 choices for handling their bank account. The program works fine but I am struggling to get the while loop to work so that whichever choice the user selects the correct choice appears but for some reason it's not doing a choice based on the user's selection. And i would also like to know how to show the transaction history that the user's done based on their deposits and transactions.

#include <stdio.h>
#include <stdlib.h>

float dep(float *maininitial, float *y);
float withdrawcash(float *maininitial, float *y);
float mainaccount(float *mainintial, float *y);
float transtosavings(float *savingsinitial, float *y);
float multiply(float *maininitial, float *interest);


int main()
{
float maininitial;
float savinginitial;
float depositamount;
float withdrawamount;
float transferamount;
int decesion = 10;
int j = 10;
int i = 0;
float interest;

printf("What is the current amount in your main account?\n");
scanf("%f", &maininitial);
printf("What is the current amount in your savings account?\n");
scanf("%f", &savinginitial);


printf("Please choose the options you want:\n\n");

printf("1. Deposit\n\n");
printf("2. Withdraw\n\n");
printf("3. Transfer money from main account to savings\n\n");
printf("4. Transfer money from savings account to main\n\n");
printf("5. Interest you'll be getting over the months\n\n");
printf("6. End process\n\n");
printf("Enter your number of choice here: ");
scanf("%d", &decesion);

while (decesion != 6) {
if (decesion = 1)
{
printf("Please input the amount you'd like to deposit from your account:\n");
scanf("%f", &depositamount);

dep(&maininitial, &depositamount);

if (maininitial > 0) {
printf("The deposit was successful, your account now has \x9C%2.f", maininitial);
}
else if (maininitial < 0) {

printf("Your deposit was unsuccessful because you entered an invalid numbed.");
}

}
if (decesion = 2) {
printf("Please enter the amount you'd like to withdraw:\n\n");
scanf("%f", &withdrawamount);

withdrawcash(&maininitial, &withdrawamount);

if (withdrawamount > 0) {
if (maininitial < -1000)
{
printf("\nYou have reached your withdrawal limit, your account is now cancelled\n");
}
else if (maininitial >= -1000) {
printf("The withdraw was successful, you now have \x9C%2.f", maininitial);
}
if (withdrawamount < 0) {
printf("The withdraw was invalid");
}
}
}
if (decesion = 3) {
printf("Choose the amount you like to send to the saving account:\n\n");
scanf("%f", &transferamount);

mainaccount(&maininitial, &transferamount);
transtosavings(&savinginitial, &transferamount);

if (transferamount > 0) {
printf("Transfer was successful, the amount that's in your main account now is ");
printf("\x9C%2.f and the amount that's now in your savings account is \x9C%2.f", maininitial, savinginitial);
}
else if (transferamount < 0)
{
printf("The amount you wish to send is invalid.");
}
}
if (decesion = 4) {

printf("Choose the amount you'd like to send your main account:\n\n");
scanf("%f", &transferamount);

mainaccount(&savinginitial, &transferamount);
transtosavings(&maininitial, &transferamount);

if (transferamount > 0) {
printf("Transfer was successful, the amount in your main account is ");
printf("\x9C%2.f and the amount that's now in your savings account is \x9C%2.f", maininitial, savinginitial);
}
if (transferamount < 0)
{
printf("The amount you wish to send is invalid.");
}
}
if (decesion = 5) {

printf("\nHow many months would you like to calculate?\n");
scanf("%d", &j);

for (i = 0; i < j; i++)
{
if (maininitial < 0 && maininitial> -1000)
{
interest = 20;
multiply(&maininitial, &interest);
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);
}
//over draft below -100
else if (maininitial < -100 && maininitial > -1000)
{
interest = 40;
multiply(&maininitial, &interest);
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);


}
//over draft below -500
else if (maininitial < -500 && maininitial > -1000)
{
interest = 80;
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);

multiply(&maininitial, &interest);
}
//stops the code if the overdraft is below -1000
else if (maininitial < -1000)
{
printf("\nYou have past the overdraft limit so your account is cancelled\n");
return 0;
}
//account is less than or equal to 100, 10% interest
else if (maininitial <= 100)
{
interest = 10;
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);
multiply(&maininitial, &interest);


}
//account is less than or equal to 200, more than 100, 50% interest
else if (maininitial > 100 && maininitial <= 200)
{
interest = 50;
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);
multiply(&maininitial, &interest);

}
//account is less than 500, more than 200, 80% interest
else if (maininitial > 200 && maininitial < 500)
{
interest = 80;
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);

multiply(&maininitial, &interest);

}
//account is more than or equal to 500, 90% interest
else if (maininitial >= 500)
{

interest = 90;
printf("\nThe amount next month in the account will be \x9C%0.2f\n", maininitial);

multiply(&maininitial, &interest);
}
}
}

}

}



float multiply(float *x, float *y)
{
*x = *x * ((*y / 100) + 1);

return *x;
}

float dep(float *maininitial, float *y)
{
*maininitial = *maininitial + *y;

return *maininitial;
}
float withdrawcash(float *maininitial, float *y)
{
*maininitial = *maininitial - *y;

return *maininitial;
}
float mainaccount(float *maininitial, float *y)
{
*maininitial = *maininitial - *y;

return *maininitial;
}
float transtosavings(float *savingsinitial, float *y)
{
*savingsinitial = *savingsinitial + *y;

return *savingsinitial;
}

Post a Reply

Replies

Oldest  Newest  Rating
+1 Dan P · November 27, 2015
Hi Glen,

The problem is that your if statement is,

if (decesion = 1)

This will always be true, because you are setting the variable decesion to 1.

The correct version would be if (decesion == 1).

You have done this for all of your if statements, so you should update it throughout.

You could also consider using a switch statement.

Dan
  • 1

C

107,322 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator