我有这样的工作,似乎像一个ATM,但我的问题是我想更新余额,但我不能。例如,当我第一次检查余额时,它会给出“0”,那么如果我再次存入“200”时,我再次检查余额,现在给我“200”,然后如果我想撤回“100”当我检查余额时,应该给我“100”。但我在传递函数中的值时遇到了问题。这是我的工作。请帮帮我。哦顺便说一句,即时通讯使用DEV C +Turbo C在函数中传递值
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// Declaring Functions that exist in the program.
int menu();
// End
// Main method at top, just to help with readability. And it can use the functions since we have already told main they exist.
int main()
{
int a = 0;
int option;
int atmDeposit();
int atmWithdrawal(int balance);
int atmCheck(int z);
system("cls");
do
{
option = menu();
switch(option)
{
case 1:
atmDeposit();
break;
case 2:
atmWithdraw(a);
break;
case 3: atmCheck(a);
break;
case 4:
printf("\nGoodbye!");
system("pause");
exit(0);
default:
printf("\nInvalid!\n");
break;
}
}
while (option != 4);
getch();
return 0;
}
int menu()
{
int op;
system("cls");
printf("What do you want to do?: \n");
printf("1 - Deposit\n");
printf("2 - Withdraw\n");
printf("3 - Check Balance\n");
printf("4 - Exit\n\n");
printf("Enter Choice: ");
scanf("%d",&op);
return op;
}
// End
// to check balance
int atmCheck(int z)
{
printf("\nYour Balance is P%d\n",z);
system("pause");
return z;
}
// End check balance
// to Deposit
int atmDeposit()
{
int deposit, a=0;
printf("\nHow much money do you want to deposit?: P");
scanf("%d", &deposit);
a += deposit;
printf("%d",a);
system("pause");
return a;
}
// end deposit
// to withdraw
int atmWithdraw(int balance)
{
int withdraw;
printf("\nHow much money do you want to withdraw?: P");
scanf("%d", &withdraw);
balance -= withdraw;
printf("%d",balance);
system("pause");
return balance;
}
// end withdraw
当您在存款后检查余额时,您确定它会给您200吗?它给了我0。 –