#include using namespace std; bool Cashbook(int& total) { int income, outgo; int sw; cout << "収入なら 1、支出なら 2、それ以外なら終了です: " << ends; cin >> sw; switch (sw) { case 1: cout << "収入はいくらですか? " << ends; cin >> income; total += income; break; case 2: cout << "支出はいくらですか? " << ends; cin >> outgo; total -= outgo; break; default: return true; } return false; } int main() { const int max_count = 20; int total; total = 10000; cout << "現在の所持金は " << total << " 円になります。" << endl; // (max_count)回まで記録を付けられます. for (int i = 0; i < max_count; i++) { if (Cashbook(total)) break; } cout << "現在の所持金は " << total << " 円になります。" << endl; return 0; }