C++ 資料型別示例
實際示例
這是一個真實生活中的例子,展示瞭如何使用不同的資料型別來計算和輸出多個專案的總成本。
示例
// 建立不同資料型別的變數
int items = 50;
double cost_per_item = 9.99;
double total_cost = items * cost_per_item;
char currency = '$';
// 列印變數
cout << "物品數量: " << items << "\n";
cout << "每件物品價格: " << cost_per_item << "" << currency << "\n";
cout << "總計金額 = " << total_cost << "" << currency << "\n";
自己動手試一試 »