0
我需要從以下程序中添加一個減值,但是當我到達添加部分時出現錯誤,如何在添加「宿舍,鎳幣,硬幣和便士」後仍然顯示它。C++私有和公共函數
當我到達添加部分時,我該如何得到8?請幫助我。
#include <iostream>
#include <iomanip>
using namespace std;
class Purse
{
private:
int quarters;
int dimes;
int nickels;
int pennies;
public:
void display_purse(int, int, int, int);
int insert_money(int, int, int, int);
int remove_money(int,int,int,int);
};
int main()
{
int qua, dim, nic, pen;
int quaa, dimm, nicc, penn;
int quaaa, dimmm, niccc, pennn;
cout << "Enter the number of Quarters :" << endl;
cin >> qua;
cout << "Enter the number of Dimes :" << endl;
cin >> dim;
cout << "Enter the number of Nickels :" << endl;
cin >> nic;
cout << "Enter the number of Pennies :" << endl;
cin >> pen;
Purse purse1;
purse1.display_purse(qua, dim, nic, pen);
cout << endl << "Current content of the purse: " << qua << " quarters " << dim << " dimes " << nic << " nickels " << pen << " pennies " << endl << endl;
cout << "or " << qua/4 + dim/10 + nic/20 + pen/100 << " dollars" << endl << endl;
//starts adding
cout << "Enter the number of Quarters to add : " << endl;
cin >> quaa;
cout << "Enter the number of Dimes to add : " << endl;
cin >> dimm;
cout << "Enter the number of Nickels to add : " << endl;
cin >> nicc;
cout << "Enter the number of Pennies to add : " << endl;
cin >> penn;
cout << endl << "The amount after entered is :" << purse1.insert_money(quaa, dimm, nicc ,penn) << endl << endl;
//starts removing
cout << "Enter the number of Quarters to remove : " << endl;
cin >> quaaa;
cout << "Enter the number of Dimes to remove : " << endl;
cin >> dimmm;
cout << "Enter the number of Nickels to remove : " << endl;
cin >> niccc;
cout << "Enter the number of Pennies to remove : " << endl;
cin >> pennn;
cout << endl << "The amount after entered is :" << purse1.remove_money(quaaa, dimmm, niccc, pennn) << endl;
cout << "or " << quaaa/4 + dimmm/10 + nic/20 + pennn/100 << " dollars" << endl << endl;
return 0;
}
void Purse::display_purse(int x, int y, int z, int a)
{
quarters = x;
dimes = y;
nickels = z;
pennies = a;
}
int Purse::insert_money(int quaa, int dimm, int nicc, int penn)
{
quarters += quaa;
return quarters;
dimes += dimm;
return dimes;
nickels += nicc;
return nickels;
pennies += penn;
return pennies;
}
int Purse::remove_money(int quaaa, int dimmm, int niccc, int pennn)
{
quarters -= quaaa;
return quarters;
dimes -= dimmm;
return dimes;
nickels -= niccc;
return nickels;
pennies -= pennn;
return pennies;
}
四個參數「int,int,int,int」是什麼意思?這太可怕了。 – gnasher729 2014-11-03 17:38:31
你需要一些基本的C++課程。在這種情況下,你有多個'return'語句。第一個返回下面的代碼從不執行。 – 2014-11-03 17:38:35
您需要告訴我們您收到的錯誤。 – Philipp 2014-11-03 17:44:15