C:警告:“withdrawal_amt'可能在这个函数中使用未初始化 [英] C: warning: ‘withdrawal_amt’ may be used uninitialized in this function
问题描述
我写一个程序为我介绍到C级,并不断收到一些警告,当我尝试用gcc来编译。
下面是我的code:
INT的main()
{
浮动平衡;
浮beg_balance;
浮withdrawal_amt;
浮deposit_amt;
浮动量;
INT total_withdrawals;
INT total_deposits;
INT选择;print_greeting();的printf(让我们与您的期初余额开始);
beg_balance = get_positive_value();
做
{
print_menu();
scanf函数(%d个,&安培;选择);开关(选择)
{
案件中退出:
get_positive_value();
余额=撤离(平衡,withdrawal_amt,数量);
打破;
案例押金:
get_positive_value();
余额=存款(余额,deposit_amt,数量);
打破;
病例摘要:
print_receipt(total_withdrawals,total_deposits,beg_balance,平衡,\\
withdrawal_amt,deposit_amt);
打破;
案例QUIT:
打破;
默认:printf的(无效的选择);
打破;
}
}
而(选择= 4!);返回0;
在编译时我正的错误是这样的:
project.c:在函数'主':
project.c:46:警告:withdrawal_amt'可能在这个函数中使用未初始化
project.c:46:警告:'量'可能在这个函数中使用未初始化
project.c:50:警告:deposit_amt'可能在这个函数中使用未初始化
project.c:53:警告:total_withdrawals'可能在这个函数中使用未初始化
project.c:53:警告:total_deposits'可能在这个函数中使用未初始化
任何想法,为什么?谢谢
编辑:
现在我有麻烦创建用于打印出账户的交易历史寄存器功能。它应该打印出开头和期末余额,以及显示发生的所有交易(存款和提款)的表。任何帮助将大大AP preciated
浮动平衡;
浮beg_balance;
浮withdrawal_amt;
浮deposit_amt;
您从未它们的属性的任何值。这就像如果你写:
情况下押金:
get_positive_value();
余额=存款(余额(浮点),金额);
打破;
您需要初始化他们像:
浮withdrawal_amt = 0.0;
I am writing a program for my intro to C class and keep getting some warnings when I try to compile with gcc.
Here is my code:
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;
The errors I am getting when compiling is this:
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
Any ideas why? Thank you
EDIT:
Now i am having trouble creating a register function that is used to print out the transaction history of the account. It should print out the beginning and ending balances, as well as a table that shows all transactions (Deposits and Withdraws) that have occurred. Any help would be greatly appreciated
float balance;
float beg_balance;
float withdrawal_amt;
float deposit_amt;
You never attribute them any value. it's like if you wrote :
case DEPOSIT:
get_positive_value();
balance = deposit(balance, (float), amount);
break;
You need to init them like :
float withdrawal_amt = 0.0;
这篇关于C:警告:“withdrawal_amt'可能在这个函数中使用未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!