我得到以下代碼的錯誤消息,但它根本沒有意義。你能檢查這段代碼並告訴你有什麼問題嗎?已在相關產品線上評論了該代碼。預期';'在聲明的末尾
#import <Foundation/Foundation.h>
typedef struct {
float exchangeRate;
double budget;
double euroTransaction;
} budget;
int main(int argc, const char * argv[])
{
budget vacationBudget;
void spendDollars (double dollars) { //Expected ';' at end of declaration
vacationBudget.budget -= 100;
}
void chargeEuros(double euros) {
vacationBudget.euroTransaction = euros*vacationBudget.exchangeRate;
vacationBudget.budget -= vacationBudget.euroTransaction;
}
vacationBudget.exchangeRate = 1.2500;
vacationBudget.budget = 1000.00;
double numberDollars = 100;
double numberEuros = 100;
spendDollars(numberDollars);
NSLog(@"Converting %.2f US dollars into euros leaves $%.2f", numberDollars, vacationBudget.budget);
NSLog(@"Charging %.2f euros leaves $%.2f", numberEuros, vacationBudget.budget);
return 0;
}
我看到這個目標C.我相信有一種方法來告訴GCC編譯器,例如,允許對函數內聲明的功能,即使這種行爲是不默認情況下允許。如果你絕對不想要main之外的函數,可能有辦法做到這一點。 – 2012-04-13 21:48:58