操作后保存其值的变量

时间:2017-03-21 21:28:54

标签: c++

该程序的目的是成为菜单驱动的检查和平衡程序。 我试图得到变量"平衡"记住在完成特定操作后它所拥有的值。我对C ++很新,我无法在任何地方找到这些信息。

int main(void)
{
double balance, deposit, withdraw;
char select;

std::cout << "Welcome to the check balancing program." << std::endl;
std::cout << "Please enter the current balance : " << std::endl;
std::cin >> balance;
std::cout << "Current balance : " << balance << std::endl;


do
{
std::cout << "please make your selection. \n";
std::cout << "W/w : Withdraw, " << "D/d : Deposit, " << "E/e : Ex  <<std::endl;
    std::cin >> select;

    switch (select)
    {
        case 'W' : case 'w':
            std::cout << "Please enter a withdrawal amount : ";
            std::cin >> withdraw;
            std::cout << "withdraw : " << withdraw << std::endl;
            std::cout << "Remaining balance : " << (balance = balance  - withdraw) << std::endl;
            break;
        case 'D' : case 'd':
            std::cout << "Please enter a deposit amount : ";
            std::cin >> deposit;
            std::cout << "deposit : " << deposit << std::endl;
            std::cout << "Remaining balance : " << (balance = balance + deposit) << std::endl;
            break;
        case 'E' : case 'e':
            std::cout << "The new balance : " << balance <<   std::endl;
            std::cout << "Thank you for using check balance program.   Goodbye." << std::endl;
            break;
        default:
            std::cout << "You have entered an invalid code. Please   try again." << std::endl;
        }
} while (select != 'e');
}

1 个答案:

答案 0 :(得分:-1)

在“存款”案例陈述中,您需要通过为变量 def calculateEuclidian(self, place): count = 0; for key, value in self.matrix.items(): if(key[1] == place and value == 1): count += 1 euclidian = math.sqrt(count) return euclidian 分配原始余额加存款的总和来保存新值,该余额应为balance。所以:

balance + deposit

然后你可以打印出结果:

balance = balance + deposit