我試圖重新建立一個收銀程序。 我有有一個名字僱員對象和折扣%卡訪問方法C++
staffMember me ("tom", 20);
我要折扣申請總收銀的。如果我通過了折扣爲使用me.getDiscountPercent這樣
cashy.applyStaffDiscount(me.getDiscountPercent());
void cashRegister::applyStaffDiscount(int discount){
total = (total/100)*(100-discount);
}
但是我想CIN的staffMember名字,所以我可以有不同折扣不同staffMembers整數參數我的方法的工作原理。我這樣做是不工作
string employee;
cout << "Enter name: ";
cin >> employee;
cashy.applyStaffDiscount(employee);
方法:
void cashRegister::applyStaffDiscount(string employee){
total = (total/100)*(100-employee.getDiscountPercent());
}
感謝湯姆
employee是一個沒有getDiscountPercent()方法的字符串。如果你有一個名字和折扣基地,然後寫一個方法,將名稱作爲參數並返回折扣。 –
「employee」的數據類型是字符串。字符串類(來自std命名空間)沒有名稱爲「getDiscountPercent()」的任何方法。 – Jaywalker
您可以將員工存儲在其姓名(字符串)是關鍵字的地圖中。 –