そのため、このプログラムのトラブルシューティングを行っており、以前に質問したことがあります。私は他の人のアドバイスを真剣に受け止め、それを自分のプログラムに適用しましたが、まだうまくいきません. これは、変更された (ただし短縮された) コードです。
#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
ご覧のとおり、ループが再開するたびに、「Withdraw、deposit、or quit:」という行が 2 回出力されます。理由を知っている人はいますか?どんな助けでも大歓迎です。私は C++ に関する限り初心者のプログラマーなので、どんな助けも大歓迎です。