1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unknown error please help

Discussion in 'C' started by bsudhir6, Jan 8, 2011.

  1. bsudhir6

    bsudhir6 New Member

    Joined:
    Apr 4, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    /* Calculate a student's average score for a  course with 4 quizzes, 2 midterms and 
         a final. The quizzes are weighted 30%, the midterms 40%, & the final 30% 
         
         @author:Sudhir
         @Date and time: 1/8/2011 5:11:19 PM
    */
    
    #include<stdio.h>
    #define QUIZ_WEIGHT 30
    #define MIDTERM_WEIGHT 40
    #define FINAL_WEIGHT 30
    #define QUIZ_MAX 400.00
    #define MIDTERM_MAX 200.00
    #define FINAL_MAX 100.0
    
    int main(int argc,char *argv[])
    {
        //Local Declarations
        int quiz1;
        int quiz2;
        int quiz3;
        int quiz4;
        int totalQuiz;
        int midterm1;
        int midterm2;
        int totalMidterm;;
        int final;
        
        float quizPercent;
        float midtermPercent;
        float finalPercent;
        float totalPercent;
        
        //Statements
        printf("\n===========================Quizes===========================\n");
        printf("Enter the score of Quiz-1: \n");
        scanf("%d", &quiz1);
        printf("Enter the score of Quiz-2: \n");
        scanf("%d", &quiz2);
        printf("Enter the score of Quiz-3: \n");
        scanf("%d", &quiz3);
        printf("Enter the score of Quiz-4: \n");
        scanf("%d", &quiz4);
        
        printf("\n===========================Midterm===========================\n");
        printf("Enter the score of Midterm-1: \n");
        scanf("%d", &midterm1);
        printf("Enter the score of Midterm-2: \n");
        scanf("%d", &midterm2);
        
        printf("\n===========================Final===========================\n");
        printf("Enter the score of final: \n");
        scanf("%d", &final);
        printf("\n");
        
        totalQuiz = quiz1 + quiz2 + quiz3 + quiz4;
        totalMidterm = midterm1 + midterm2;
        
        quizPercent = (float)totalQuiz * QUIZ_WEIGHT / QUIZ_MAX;
        
        midtermPercent = (float)totalMidterm * MIDTERM_WEIGHT / MIDTERM_MAX;
        
        finalPercent = (float)final * FINAL_WEIGHT / FINAL_MAX;
        
        printf("Quiz-1  %4d \n", quiz1);
        printf("Quiz-2  %4d \n", quiz2);
        printf("Quiz-3  %4d \n", quiz3);
        printf("Quiz-4  %4d \n", quiz4);
        printf("Quiz Total %4d \n\n", totalQuiz);
        
        printf("Midterm-1  %4d \n", midterm1);
        printf("Midterm-2  %4d \n", midterm2);
        printf("Midterm Total %4d \n\n", totalMedterm);
        
        printf("Final      %4d\n\n", final);
        
        printf("Quiz       %6.1f %% \n", quizPercent);
        printf("Midterm    %6.1f %% \n", midtermPercent);
        printf("Final      %6.1f %% \n", finalPercent);
        printf("-------------------\n");
        printf("Total      %6.1f %% \n", totalPercent);
        
        return 0;
    }//main
    
    errors returned by visual c++ command prompt are...
    Code:
    C:\Documents and Settings\Sudhir\My Documents\C Programs\TextBook>cl StudMar.c
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    StudMar.c
    StudMar.c(27) : error C2143: syntax error : missing ';' before 'type'
    StudMar.c(29) : error C2143: syntax error : missing ';' before 'type'
    StudMar.c(30) : error C2143: syntax error : missing ';' before 'type'
    StudMar.c(31) : error C2143: syntax error : missing ';' before 'type'
    StudMar.c(32) : error C2143: syntax error : missing ';' before 'type'
    StudMar.c(53) : error C2065: 'final' : undeclared identifier
    StudMar.c(59) : error C2065: 'quizPercent' : undeclared identifier
    StudMar.c(61) : error C2065: 'midtermPercent' : undeclared identifier
    StudMar.c(63) : error C2065: 'finalPercent' : undeclared identifier
    StudMar.c(73) : error C2065: 'totalMedterm' : undeclared identifier
    StudMar.c(81) : error C2065: 'totalPercent' : undeclared identifier
    
    errors returned by lcc are...
    Code:
    C:\Documents and Settings\Sudhir\My Documents\C Programs\TextBook>lc StudMar.c
    Error studmar.c: 73  undeclared identifier 'totalMedterm'
    Warning studmar.c: 73  possible usage of totalMedterm before definition
    Warning studmar.c: 32  possible usage of totalPercent before definition
    1 error, 2 warnings
    1 error
    
     
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    Code:
    /* Calculate a student's average score for a  course with 4 quizzes, 2 midterms and 
         a final. The quizzes are weighted 30%, the midterms 40%, & the final 30% 
         
         @author:Sudhir
         @Date and time: 1/8/2011 5:11:19 PM
    */
    
    #include<stdio.h>
    #define QUIZ_WEIGHT 30
    #define MIDTERM_WEIGHT 40
    #define FINAL_WEIGHT 30
    #define QUIZ_MAX 400.00
    #define MIDTERM_MAX 200.00
    #define FINAL_MAX 100.0
    
    int main(int argc,char *argv[])
    {
        //Local Declarations
        int quiz1;
        int quiz2;
        int quiz3;
        int quiz4;
        int totalQuiz;
        int midterm1;
        int midterm2;
        int totalMidterm[COLOR=Red];[/COLOR]
        int final;
    [COLOR=Red]    float quizPercent=(float) QUIZ_WEIGHT / QUIZ_MAX;
        float midtermPercent= (float)MIDTERM_WEIGHT / MIDTERM_MAX;
        float finalPercent= (float)FINAL_WEIGHT / FINAL_MAX;
        //float totalPercent;
        float total=0;[/COLOR]
        //Statements
        printf("\n===========================Quizes===========================\n");
        printf("Enter the score of Quiz-1: \n");
        scanf("%d", &quiz1);getchar();
        printf("Enter the score of Quiz-2: \n");
        scanf("%d", &quiz2);getchar();
        printf("Enter the score of Quiz-3: \n");
        scanf("%d", &quiz3);getchar();
        printf("Enter the score of Quiz-4: \n");
        scanf("%d", &quiz4);getchar();
        
        printf("\n===========================Midterm===========================\n");
        printf("Enter the score of Midterm-1: \n");
        scanf("%d", &midterm1);getchar();
        printf("Enter the score of Midterm-2: \n");
        scanf("%d", &midterm2);getchar();
        
        printf("\n===========================Final===========================\n");
        printf("Enter the score of final: \n");
        scanf("%d", &final);getchar();
        printf("\n");
        
        totalQuiz = quiz1 + quiz2 + quiz3 + quiz4;
        totalMidterm = midterm1 + midterm2;
        
    
        
        printf("Quiz-1  %4d \n", quiz1);
        printf("Quiz-2  %4d \n", quiz2);
        printf("Quiz-3  %4d \n", quiz3);
        printf("Quiz-4  %4d \n", quiz4);
        printf("Quiz Total %4d \n\n", totalQuiz);
        
        printf("Midterm-1  %4d \n", midterm1);
        printf("Midterm-2  %4d \n", midterm2);
        printf("Midterm Total %4d \n\n", totalMidterm);//
        
        printf("Final      %4d\n\n", final);
        
    [COLOR=Red]    total=quizPercent*totalQuiz+midtermPercent*totalMidterm+finalPercent*final;
        printf("\nAverage score calculation");
        printf("\n===========================\n");
        printf("Quiz    score    %6.1f \n", quizPercent*totalQuiz);
        printf("Midterm score    %6.1f \n", midtermPercent*totalMidterm);
        printf("Final   score    %6.1f \n", finalPercent*final);
        printf("-----------------------------\n");
        printf("average score    %6.1f \n",total );[/COLOR]
        getchar();
        return 0;
    }//main
    
    
    
     
    shabbir likes this.

Share This Page