我正在为我的 C 类介绍编写一个程序,并在尝试使用 gcc 编译时不断收到一些警告。
这是我的代码:
int main ()
{
float balance;
float beg_balance;
float withdrawal_amt;
float deposit_amt;
float amount;
int total_withdrawals;
int total_deposits;
int selection;
print_greeting ();
printf("Let's begin with your beginning balance");
beg_balance = get_positive_value();
do
{
print_menu ();
scanf("%d", &selection);
switch (selection)
{
case WITHDRAWAL:
get_positive_value();
balance = withdrawal(balance, withdrawal_amt, amount);
break;
case DEPOSIT:
get_positive_value();
balance = deposit(balance, deposit_amt, amount);
break;
case SUMMARY:
print_receipt(total_withdrawals, total_deposits, beg_balance, balance, \
withdrawal_amt, deposit_amt);
break;
case QUIT:
break;
default: printf("Invalid selection");
break;
}
}
while(selection != 4);
return 0;
我在编译时遇到的错误是这样的:
project.c: In function ‘main’:
project.c:46: warning: ‘withdrawal_amt’ may be used uninitialized in this function
project.c:46: warning: ‘amount’ may be used uninitialized in this function
project.c:50: warning: ‘deposit_amt’ may be used uninitialized in this function
project.c:53: warning: ‘total_withdrawals’ may be used uninitialized in this function
project.c:53: warning: ‘total_deposits’ may be used uninitialized in this function
任何想法为什么?谢谢
编辑:
现在我无法创建用于打印帐户交易历史的注册功能。它应该打印出期初余额和期末余额,以及显示已发生的所有交易(存款和取款)的表格。任何帮助将不胜感激