2017-03-08 1 views
-6

프로그래밍을 배우려고합니다. 간단한 질문이지만 해결할 수 없습니다. 왜 오류가 발생합니까? 무엇이 잘못 되었나요? 어떻게하면됩니까? 이 문제를 해결 도와주세요 여기 [오류] : 예상 '('시간 전 '

는 문제 정의하고 내 코드 :..

enter image description here

#include<stdio.h> 

void calculateCharged(int c) { 
    int a; 
    int hours = scanf("%d", &a); 
    int totalFee = 25; 
} 

int main(void) { 

    int i; 
    int b; 
    printf("Please Enter Number of Cars "); 
    scanf("%d", &i); 
    for (b = 0; b < i; b++) { 
     calculateCharged(hours) 
     if (hours)<8 
     totalFee += hours * 0, 5 
     else if hours < 24 
     int additionalHours = hours - 7 
     totalFee += additionalHours * 5 
     totalFee += hours * 0, 5 
     else 
     int days = hours/24 
     int extraHours = hours % 24 
     totalFee += days * 50 
     totalFee += days * 24 * 0, 5 
     totalFee += extraHours * 5 
     totalFee += extraHours * 0, 5 
    } 
} 
+1

없음 이미지와 C/C++하십시오 태그. [묻는 방법] (http://stackoverflow.com/help/how-to-ask)을 읽어보십시오. –

+4

수백만 개의 오류가 있습니다. C로 책을 가져 가야합니다. – George

+2

아직 언어를 배우지 않았기 때문에 오류가 발생합니다. [좋은 초보자를 찾으십시오.] (http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) 읽고 간단한 것을 다시 시작하십시오. –

답변

0

나는 당신의 문제 정의를 읽을하지 않았지만 코드는이 구문과 논리로 정확 적어도처럼 sould :

#include<stdio.h> 

float totalFee = 0; 
int hours = 0; 

int main(void) { 

    int i; 
    int b; 
    printf("Please Enter Number of Cars "); 
    scanf("%d", &i); 

    for (b = 0; b < i; b++) { 
     scanf("%d", &hours); 
     if (hours < 8) { 
      totalFee += hours * 0.5; 
     } else if (hours < 24) { 
      float additionalHours = hours - 7; 
      totalFee += additionalHours * 5; 
      totalFee += hours * 0.5; 
     } else { 
      float days = hours/24; 
      float extraHours = hours % 24; 
      totalFee += days * 50; 
      totalFee += days * 24 * 0.5; 
      totalFee += extraHours * 5; 
      totalFee += extraHours * 0.5; 
     } 
    } 
} 
4

이 솔루션은 오류 메시지에 문자 그대로

C에서 if의 구문에는 조건 주위에 괄호가 필요합니다.

그래서

else if(hours < 24) 

그것은 첫 번째 if 허용되었다는 좋은 힌트를해야합니다.

또한 범위 주위에 중괄호가 필요하며 코드는 들여 쓰기가되지 않은 파이썬 또는 그와 비슷한 것으로 보입니다. 새로운 프로그래밍 언어를 사용하기 전에 기본 참고 자료를 읽어보십시오.