所以我一直在对这个程序进行故障排除,我之前已经问过有关它的问题。我已经认真对待其他人的建议并将其应用到我的程序中,但它仍然无法正常工作。这是修改后的(尽管缩短了)代码:
#include <iostream>
#include <string>
double balance, withdraw, deposit;
std::string choice;
void withdrawmon()
{
balance -= withdraw;
}
void depositmon()
{
balance += deposit;
}
int main()
{
std::cout << "Welcome to the Bank Program." << std::endl;
std::cout << "Enter a starting balance: ";
std::cin >> balance;
std::cin.clear();
do
{
std::cout << "Withdraw, deposit, or quit: ";
std::getline (std::cin, choice);
if(choice == "withdraw")
{
std::cout << "Enter amount to withdraw: ";
std::cin >> withdraw;
withdrawmon();
std::cout << "Your current balance is $" << balance << std::endl;
}
else if(choice == "deposit")
{
std::cout << "Enter amount to deposit: ";
std::cin >> deposit;
depositmon();
std::cout << "Your current balance is $" << balance << std::endl;
}
}
while(choice != "quit");
std::cout << "Thanks for using the Bank Program. Your final balance was $" << balance << std::endl;
return 0;
}
不会有问题,代码运行了,但是输出是这样的: https ://www.dropbox.com/s/aocn6asjr4ofcws/Broken%20Output.PNG
正如您所看到的,每当循环重新启动时,“取款、存款或退出:”行都会自行打印两次。有谁知道为什么?任何帮助表示赞赏。就 C++ 而言,我是一名新程序员,因此不胜感激。