用C++製作一個販賣紀錄器:
#include <iostream>
#include <string>
int main() {
// 宣告變數
std::string client;
std::string fruit;
std::string phone_number;
double rate;
double fee;
double fruit_price;
double total_amount;
// 讓使用者輸入資料
std::cout << "請輸入顧客名稱:";
std::cin >> client;
std::cout << "請輸入購買水果名稱(apple、banana 或 orange):";
std::cin >> fruit;
std::cout << "請輸入手機號碼:";
std::cin >> phone_number;
std::cout << "請輸入稅金(百分比):";
std::cin >> rate;
std::cout << "請輸入手續費:";
std::cin >> fee;
// 根據購買的水果種類計算價格
if (fruit == "apple") {
fruit_price = 10;
} else if (fruit == "banana") {
fruit_price = 20;
} else if (fruit == "orange") {
fruit_price = 30;
}
// 計算總金額
total_amount = fee + (fruit_price * rate) + fruit_price;
// 顯示結果
std::cout << "顧客名稱:" << client << std::endl;
std::cout << "手機號碼:" << phone_number << std::endl;
std::cout << "購買水果:" << fruit << std::endl;
std::cout << "水果價格:" << fruit_price << "$" << std::endl;
std::cout << "手續費:" << fee << "$" << std::endl;
std::cout << "總金額:" << total_amount << "$" << std::endl;
return 0;
}