2015-10-02 28 views
1

我介紹C++。我的任務是編寫一個像員工終端一樣的程序。該程序應提示客戶他們在哪個計劃(A,B或C)上的程序應該識別大寫和小寫字母。然後提示他們使用數據。計劃A是15美元,並附帶200mb的數據,每增加一百萬的超額費用爲0.06。計劃B是25美元,並附帶2000mb數據,每增加mb 0.02。 C計劃是無限的。在C++中比較手機套餐

我已經完成了所有這些。我堅持的部分是比較。如果一個人計劃在A計劃,並且說他們使用超過367mb(25.02美元)但少於784mb(50.04美元)的計劃,那麼他們必須告訴他們,如果他們改用計劃B,他們會節省多少。如果他們使用超過367mb必須告訴他們他們在計劃C中會節省多少錢。我也必須爲計劃B中那些過去那些日期的人做同樣的事情,但只有當他們的超額總計超過計劃C的價格並因此纔會有省下來的錢是他們在計劃C.

程序並不需要通知的降級計劃(即從C計劃遷移到A)僅升級。

#include <iostream> 
using namespace std; 

/* Project One 
Wriitten by A-R 
*/ 
int main() 
{ 

    char Plan_omega; 
    int  MB; 
    double Plan_Cost_A, Plan_Cost_B, Plan_Cost_C, Variation_A; 

    cout << "Which plan does the customer currently have?"<< endl;       // Input of the customer's current plan. 
    cin >> Plan_omega; 

    while (!(Plan_omega=='A') && !(Plan_omega=='B') && !(Plan_omega=='C') && // Must input either A, B, or C (upper of lower case) or it will reprompt. 
      !(Plan_omega=='a') && !(Plan_omega=='b') && !(Plan_omega=='c')) { 

     cout << "Please enter only A, B, or C" << endl; 
     cin >> Plan_omega; 
    } 

    cout << "How many MB did the customer use last month?" <<endl; 
    cin >> MB; 

    while (MB < 0 || MB > 10000) { 

     cout << "Please enter a value between 0 and 10,000" << endl; 
     cin >> MB; 
    } 

    switch (Plan_omega){ 
     case 'A': 
     case 'a': 
     cout << "The customer's total bill is $"; 
      if (MB > 200) { 
       Plan_Cost_A = 15 + ((MB - 200) * 0.06); 
      } else { 
       Plan_Cost_A = 15; 
      } 
      cout << Plan_Cost_A <<endl; 
      break; 

     case 'B': 
     case 'b': 
     cout << "The customer's total bill is $";  
      if (MB > 2000){ 
       Plan_Cost_B = 25 + ((MB - 2000) * 0.02); 
      } else { 
       Plan_Cost_B = 25; 
      } 
      cout << Plan_Cost_B <<endl; 
      break; 
     cout << "The customer's total bill is $";  

     case 'C': 
     case 'c': 
     cout << "The customer's total bill is $";  
      if (MB > -1){ 
       Plan_Cost_C = 50; 
      } else { 
       Plan_Cost_C = 50; 
      cout << Plan_Cost_C <<endl; 
      } 
      break; 




    } 
    return 0; 
}  

感謝您的協助。我上次寫了一個簡短得多的問題,每個人都要求提供更多信息。我試圖保持簡短,但失敗了。

另外,我知道有許多的辦法,使這個方案更小或添加快捷方式。我的老師特別要求以類似於我的樣子製作該程序,再次感謝。

+0

始終計算'Plan_Cost_A','Plan_Cost_B'和'Plan_Cost_C'。然後用'switch'決定哪一個輸出爲客戶賬單。然後,您可以比較A,B和C的計算成本,以檢查哪個是客戶的最佳匹配。 – JimmyB

+0

計算所有價格,並僅顯示低於用戶當前計劃價格的價格。有什麼問題?在這樣糟糕的任務中,老師通常會尋找最近學過的代碼的一些具體用法,所以仔細閱讀你的筆記,不要過多考慮。 ** K ** eep ** I ** t ** S **執行,** S ** tupid – user3791372

回答

0

您可以設置一個if...elseif區塊,將MB的值與367和748進行比較,並使用它來確定是否應該將比較結果顯示給其他計劃。

例子:

int main (void) 
{  
    char Plan_omega; 
    int MB; 
    //get the value of Plan_omega and MB 
    //Calculate Plan_Cost_A, Plan_Cost_B, and Plan_Cost_C 

    switch (Plan_omega){ 
     //code here to display their current bill 
    } 

    if (MB > 367 && MB < 748) { 
     // Calculate what they would have saved on Plan B 
    } 
    elseif (MB > 367) { 
     // Calculate what they would have saved on Plan C 
    } 
    return 0; 
} 

我不覺得這個問題屬於的你可以問堆棧溢出問題的領域內,不過,我預測它會很快被標記爲題外話。

+0

感謝您的幫助。我以前試過if,else if和(MB> 367 ....)幾乎和你寫的一樣。該程序忽略了MB參數。 –

+0

你是什麼意思,忽略了MB參數? –

+0

即使MB低於或高於我設定的值,它也會運行計算。我完全按照你的建議編碼。我昨晚做了,而且我很累,所以讓我再試一次。 –