2014-05-22 125 views
1
int main (int argc, const char * argv[]) 
{ 
    @selector(grades); 

} 

-(int)grades:(int)grade{ 
    printf("Please write down your grade:"); 
    scanf("%d", &grade);/*the grade value written has assigned to grade parameter*/ 
    printf("\n"); 

    if((grade > 100) || (grade <0)){/*This is a warning range of grades */ 
    printf("Warning!!\nYour grade is out of range\nPlease write a NUMBER between 0-100\n"); 
} 
else{/*The grade ranges are defined*/ 
    if((0<=grade) && (grade<=20)) 
     NSLog(@"Your letter grade is : F\nyou failed\n");/*NSLog has been used insted of printf*/ 
    if((21<=grade) &&(grade<=40)) 
     NSLog(@"Your letter grade is : D\nTry again\n"); 
    if((41<=grade) && (grade<=60)) 
     NSLog(@"your letter grade is : C\nNot bad\n"); 
    if((61<=grade)&&(grade<=80)) 
     NSLog(@"Your letter grade is : B\nWell Done\n"); 
    if((81<=grade)&&(grade<=100)) 
     NSLog(@"your letter grade is : A\nGreat !!\n"); 
} 
return 0; 
} 

我有在方法聲明中的問題目標C缺失背景下,我想我檢查了,但我 不能發現任何錯誤 如果你們能幫助我,這將是巨大的。 謝謝的方法聲明

+1

什麼的'@selector(等級)'?另外,不應該是'@selector(grades:)'? – Larme

+1

你想完成什麼? '@selector(等級);'沒有做任何事情 –

+0

它需要編譯檔次方法 – user3446544

回答

1

沒有爲方法沒有上下文。該方法被聲明爲對象的實例方法-,但是沒有與其關聯的類。所以在什麼情況下,該方法將被宣佈是未知的。

爲了您的情況下使用,

  int grade (int grade) 
      { 
       printf("Please write down your grade:"); 
       scanf("%d", &grade);/*the grade value written has assigned to grade parameter*/ 
       printf("\n"); 

       if((grade > 100) || (grade <0)){/*This is a warning range of grades */ 
        printf("Warning!!\nYour grade is out of range\nPlease write a NUMBER between 0-100\n"); 
       } 
       else{/*The grade ranges are defined*/ 
        if((0<=grade) && (grade<=20)) 
         NSLog(@"Your letter grade is : F\nyou failed\n");/*NSLog has been used insted of printf*/ 
        if((21<=grade) &&(grade<=40)) 
         NSLog(@"Your letter grade is : D\nTry again\n"); 
        if((41<=grade) && (grade<=60)) 
         NSLog(@"your letter grade is : C\nNot bad\n"); 
        if((61<=grade)&&(grade<=80)) 
         NSLog(@"Your letter grade is : B\nWell Done\n"); 
        if((81<=grade)&&(grade<=100)) 
         NSLog(@"your letter grade is : A\nGreat !!\n"); 
       } 
       return 0; 
      } 

      int main(int argc, const char * argv[]) 
      { 

       grade(0); 
      } 
+0

確實,這是我所取得的成就,但它是一種客觀的c方法嗎? – user3446544

+0

謝謝,我相信這個將工作 – user3446544

+0

它只是一個C方法。對於Objective C,聲明一個類並在類中聲明你的方法'grade'。然後在main中,實例化對象並調用此方法。 –

0

我有一個印象,即「缺少上下文方法聲明」(MCFMD)具有從未被完全理解的問題。

相關帖子提供一些特定的情況下,一些解決方案,但沒有任何解釋或一般的方法,可以在案件至少,例如90%的工作

問:的Objective-C 「的方法聲明缺少語境」 - 問5月13日通過user3631024

問:與構造方法聲明中缺少上下文「 - - 詢問用戶2789992是否

問:缺少方法聲明的上下文被替代的描述方法通過pdenlinger -asked 4月26日'12

同時,一些人抱怨說,他們相信MCFMD問題已經成熟,並妥善解決......我與33戰鬥MCFMD在我的代碼中,這更像是在黑暗中拍攝。我希望那些誰擁有MCFMD問題有了更多的認識分享他們寶貴的知識或任何東西走向的理解...... 非常感謝關注!