int main()
{
int money;
int cash,amount ;
int choice;
money = openAccount();
do
{
clrscr();
cout <<"1.Display balance"<<endl;
cout <<"2.Withdraw money"<<endl;
cout <<"3.Exit"<<endl;
cout <<"Enter a choice :";
cin >>choice;
if(choice == 1||choice ==2||choice==3)
{
}
else
{
clrscr();
cout <<"Invalid selection ,you could only select 1 to 3"<<endl;
cout <<"Press any key to try again....";
getch();
}
if(choice == 1)
{
clrscr();
cout <<"Your account have RM "<<money<<" still available"<<endl;
cout <<"Press any key to continue........";
getch();
}
if(choice == 2)
{
clrscr();
cout <<"Enter the sum of cash you want to withdraw :"<<endl;
cin >> cash;
amount = money - cash;
cout<<"You have withdraw RM"<<cash<<endl;
cout<<"Press any key to continue .........";
getch();
}
}
while(choice!=3);
if (choice == 3)
{
updateAccount(amount);
exit(1);
This is a simple ATM machine system source code ,everything seems properly like display balance,withdrawing but once the exit selection has made the the amount output to the text file becomes a hexadecimal number.Before that there is no problem to output the exact amount to the text file until the exit function lines add into the entire code .Any suggestion ?
You're being somewhat schizophrenic with your variables:
Your functions use doubles, but you put their return values into ints. You put the return value of openAccount() into money, and use money to tell the user how much they have left, but then you do amount = money - cash; and don't update money, and you pass the value of amount to updateAccount(). amount, therefore, doesn't necessarily have a value by the time the user exits.