Problem: If you deposit 1000-->then borrow 40000-->then withdraw 43000 and get the error "insufficient balance" --> then try again and deposit 28000. The issue here is that the balance is -31000 the second time you try instead of something around 12000. Anyone that knows why?
I've tried moving the capital "statement" into the else statement but that just made things worse. I've also tried moving it to the account stats section but that didn't work either. I'm new to this and im not really that good at problem solving so sorry if it's something obvious:/
using System;
namespace atmtest
{
class Program
{
public static void Main()
{
int balance = 0, deposit = 0, withdraw = 0, choice, loan = 0, kredit = 0, debt = 0, capital = 0;
while (true)
{
Console.WriteLine("----------------------------");
Console.WriteLine("Welcome");
Console.WriteLine("----------------------------");
Console.WriteLine("1) Deposit");
Console.WriteLine("2) Withdraw");
Console.WriteLine("3) Account stats");
Console.WriteLine("4) Borrow money");
Console.WriteLine("--------------------------------");
Console.WriteLine("Enter one of the options ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Console.Clear();
try
{
Console.WriteLine("Deposit, enter amount : ");
deposit = int.Parse(Console.ReadLine());
if (deposit > 500000)
{
Console.WriteLine("Error, max amount 500000");
}
else if (deposit < 0)
{
Console.WriteLine("Error, the amount has to be positive");
}
else
{
capital = balance + deposit;
Console.WriteLine("You have deposited " + deposit + " and your balance is now: " + capital);
}
}
catch
{
Console.WriteLine("Error, enter numbers only.");
}
break;
case 2:
Console.Clear();
Console.WriteLine("Withdraw, enter amount: ");
withdraw = int.Parse(Console.ReadLine());
capital = kredit + balance - withdraw;
balance = balance - withdraw;
if ((withdraw > balance) && (withdraw > kredit))
{
Console.WriteLine("Error, insufficent balance.");
capital = deposit;
Console.WriteLine("Try again");
}
else
{
debt = balance;
Console.WriteLine("You have withdrawn " + withdraw);
Console.WriteLine("Your current balance is " + capital);
}
break;
case 3:
Console.Clear();
Console.WriteLine("Account stats: ");
Console.WriteLine("Balance: " + capital);
Console.WriteLine("Amount of money borrowed ( loan ): " + kredit);
Console.WriteLine("Debt: " + debt);
Console.WriteLine("You have used " + debt );
break;
case 4:
Console.Clear();
Console.WriteLine("how much do you want to borrow? Max amount is 50000.");
Console.WriteLine("Enter amount: ");
loan = int.Parse(Console.ReadLine());
kredit = loan + kredit;
if (kredit > 50000)
{
Console.WriteLine("You cannot borrow this amount, max amount is 50000");
kredit = kredit - loan;
}
else if (kredit <= 50000)
{
Console.WriteLine("You have been granted " + loan);
}
break;
}
}
}
}
}
