如何让编译器检查语句的左侧和右侧?如果我没记错的话,我认为在 C 语言中,如果你有的话,它会左右读取&&
或者||
....所以当我为 C++ 查找这个时,它说只检查左边是否为真....什么我需要的是能够检查双方是否都是真的。
所以:
//Transactions has been initialized to 0
1. if deposit OR withdraw are greater than or equal to 1, add 1 to variable transactions.
2. if deposit AND withdraw are BOTH greater than or equal 1, then add 2 to variable transactions.
3. else if BOTH are less than 1, transaction is 0.
if (deposit >= 1 || withdraw >=1)
{
transactions = transactions + 1;
cout << "Transactions: " << transactions << endl;
}
else if (deposit >= 1 && withdraw >=1)
{
transactions = transactions + 2;
cout << "Transactions: " << transactions << endl;
}
else
{
cout <<"Transactions: " << transactions << endl;
}
我遇到的这个问题是,它只读取左侧,因此事务只返回 1。
感谢您的时间!
编辑
https://ideone.com/S66lXi (account.cpp)
https://ideone.com/NtwW85 (main.cpp)