我的任務要求的輸出,看起來類同的部份:一個「CIN」多輸入
輸出示例: 輸入產品類型和銷售數量(輸入Z來終止):A 2
總銷售產品A = $ 5.97
該字母代表物品的價格,下面的數字代表物品的數量。那麼,我將如何讓我的cin獲得對象和數量? 我目前有:
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double ProfitA, ProfitB, ProfitC;
double TotalA = 0;
char type;
int quant;
ProfitA = (1.99) * quant;
ProfitB = (2.99) * quant;
ProfitC = (3.99) * quant;
cout << "Enter product type and quantity sold (enter -1 to stop)\n\n";
cin >> type >> quant;
switch (type)
{
case 'A':cout << "Total sales of product A =" << ProfitA << "\n";
break;
case 'B':cout << "Total sales of product B =" << ProfitB << "\n";
break;
case 'C':cout << "Total sales of product C =" << ProfitC << "\n";
break;
}
出了什麼問題,你有什麼? –
直到獲得數量後才計算利潤。 –