2012-09-14 37 views
0

我在編譯下面的程序時遇到此錯誤,我無法弄清楚原因。scanf調用中的類型的無效操作數

39:19: error: invalid operands of types ‘const char [5]’ and ‘long long int’ to binary ‘operator&’ 

這是代碼。

int 
main(void) 
{ 
    long long d, p; 

    // Ask for number for the numbers of days as long as input is between 28 and 31 
    do 
    { 
     printf("How many days are in your month?\n"); 
     scanf("%lld" &d); // This is the line with the error 
    } 
    while (d<28 || d>31); 

    // Ask user for number of pennies for day 1 as long as input is not negative 
    printf("How many Pennies do you have?\n"); 
    do 
    { 
     scanf("%lld", &p);  
    } 
    while (p<0); 

    //sum up the pennies 
    int i; 
    for (int i=0; i<=d-1; i++); 
    { 
     p = (p * 2); 
    } 

    // Format and print the total (currently * instead of/for troube-shooting) 
    double total; 
    total = (p * 100); 
    printf("Your ending amount it $%.2f.\n, total");   
} 
+2

我覺得如果你糾正你的問題的錯誤將是在未來的讀者非常混亂。答案似乎是無稽之談。 – wildplasser

回答

2

您忘記了scanf("%lld" &d);的逗號。這導致它將參數解釋爲scanf,這是由於某些字符與一個數字BITAND結果。

將其更改爲:

scanf("%lld", &d); 
+0

對不起,我錯過了....不會再發生。謝謝! –

+0

@CalebLawrence,發生了。我必須承認我不記得留下一個逗號,但我昨天剛剛離開了一個小點去訪問一個會員。 – chris

+0

哈哈。好。謝謝。 :) –

3

應該

scanf("%lld", &d); //not scanf("%lld" &d); 
+0

非常感謝! –

+0

@CalebLawrence沒問題。以下是我如何解決這些問題的方法。直到代碼編譯之前,我開始評論一些事情。分而治之。 – bioffe

相關問題