2013-06-22 78 views
-1

我在編寫「if」「else」語句時遇到了困難,但我在運行該程序時無法執行。如果else語句不會執行

#include <iostream> 
using namespace std; 
int main() 
{ 
    double vehicle_price, options_price, new_result, end_solution, sales_tax_region, v8_price, sales_tax; 
    double region_0, region_1, region_2; 

    // This where the sales person will ask the customer if a v8 is desired. 
    cout << "vehicle_price:$"  ; 
    cin >> vehicle_price  ; 
    cout << "options_price:$" ; 
    cin >> options_price  ; 

    // At this time the customer would be asked which region they live in. 

    // enter 6.5 or 7.0 to indicate if region_1 or region_2 is where they live 

    cout << "v8_price:$" ; 
    cin >> v8_price  ; 
    cout << "sales_tax_region:"  ; 
    cin >> sales_tax_region   ; 

    // At this point the price of the v8 would be entered if it is required. 

    if (region_1 <= 500.00) 
    { 
     sales_tax= region_1 *.65; 
    } 
    if (region_2 <= 550.0) 
    { 
     sales_tax_region= region_2 * .70; 
    } 
    else 
    { 
     if (region_0 <= 0.0); 
    } 
    sales_tax_region= region_1 * .65; 
    { 
    } 
    new_result= (options_price + vehicle_price+ v8_price)*(sales_tax_region/100) ; 
    end_solution = (new_result + options_price + vehicle_price); 
    cout << "Total_price_of_the_vehicle:$" << end_solution << endl ; 

    return 0; 
} 

這是我使用請使用「的if-else」結構,以確定要使用的V8價格的要求。使用另一個「if-else」結構來確定要根據地區代碼選擇的銷售稅額值。

我完全失去了「如果」「其他」部分。

+1

什麼是你所面臨的問題? –

+4

'if(region_0 <= 0.0);'?那是什麼';'在那裏做?爲什麼空白區塊在下面幾行?請格式化您的代碼。 – Mat

+0

你的括號在結尾處是錯誤的。 –

回答

3

變化

else 
{ 
if (region_0 <= 0.0); 
} 
sales_tax_region= region_1 * .65; 
{ 
} 

else 
if (region_0 <= 0.0) { 
    sales_tax_region= region_1 * .65; 
} 
+0

如果你能夠正確縮進代碼以使其可讀,那將會很好。 –