2014-10-09 23 views
0

我剛剛開始與C++,使用xcode。我試圖寫一個簡單的,如果用戶工作x數量的用戶得到支付的金額,程序。我不確定我是否正確,但是我無法測試它,因爲我在第一個{'字符串上出現錯誤「Expected unqualified-id」。這是列出的唯一錯誤,我無法弄清楚如何解決它。問題與意外的不合格id錯誤

#include <iostream> 

using namespace std; 

int main() 

int user; 
int salary1 = user * 12; 
int salary2 = (user * 18) + 480; 
{ // this is the line I'm receiving error. 
    cout << "Enter the number of hours you worked this week"; 
    cin >> user; 

    if (user <= 40) 
    { 
     cout << "You made" << salary1 << "this week!" 
    } 
    else (user > 40) 
    { 
     cout << "You made" << salary2 << "this week!!!" 
    } 
return 0; 
} 
+1

'int main(){/ * <--- {should be here * /'。這絕對是**不是你唯一的錯誤。 – 2014-10-09 04:16:19

回答

1

在int main塊內聲明變量並在收到用戶輸入後計算工資。

#include <iostream> 

using namespace std; 

int main() 
{ 
    int user; 
    cout << "Enter the number of hours you worked this week"; 
    cin >> user; 
    int salary1 = user * 12; 
    int salary2 = (user * 18) + 480; 
    if (user <= 40) 
    { 
     cout << "You made" << salary1 << "this week!" 
    } 
    else (user > 40) 
    { 
     cout << "You made" << salary2 << "this week!!!" 
    } 
    return 0; 
} 
1

大括號去整函數體周圍:

int main() 
{ // <--- function body starts here 
    int user; 
    // rest of function body 
} // <--- function body ends here 

您也想後計算的salary1salary2值你讀過的user值。