Question

In: Computer Science

C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A =...

C Programming

Debug -> error: expected expression before 'score'


typedef enum LetterGrade {
    A = 4,
    B = 3,
    C = 2,
    D = 1,
    F = 0
} score;

score getLetterGradeFromAverage(const double avg)
{
    if (avg >= 90)
        return score::A;         // error here
    else if (avg >= 80)
        return score::B;        // error here
    else if (avg >= 70)
        return score::C;       // error here
    else if (avg >= 60)
        return score::D;       // error here
    else
        return score::F;        // error here
}

Solutions

Expert Solution

/*

In standard c, things to the left of "::" MUST BE STRUCT, enums don't count.

*/

#include<stdio.h>
typedef enum LetterGrade {
A = 4,
B = 3,
C = 2,
D = 1,
F = 0
}score ;


score getLetterGradeFromAverage(const double avg)
{

if (avg >= 90)
return A;   
else if (avg >= 80)
return B;
else if (avg >= 70)
return C;   
else if (avg >= 60)
return D;   
else
return F;
}

int main(){
   int avg = 90;
   if(A == getLetterGradeFromAverage(avg)){
       printf("A");
   }else if(B == getLetterGradeFromAverage(avg)){
       printf("B");
   }else if(C == getLetterGradeFromAverage(avg)){
       printf("C");
   }else if(D == getLetterGradeFromAverage(avg)){
       printf("D");
   }else if(F == getLetterGradeFromAverage(avg)){
       printf("F");
   }
}


Related Solutions

C++ Programming Enum - Structure - Array You are asked to develop software for HR department...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department to calculate employee’s weekly salary. The program should contain the following information about a student by declaring a struct: Name (string of characters)        Employee ID (string of characters)        Level (ENGINEER, MANGER, DIRECTOR)        Hourly Rate (floating-point number)        Working Hours (floating-point number)        Weekly Salary (floating-point number) Your program will read an employee data and print the information of employee’s Name, Employee...
Im getting an error on the Player.h class. Error reads expected initializer before player. I have...
Im getting an error on the Player.h class. Error reads expected initializer before player. I have put a comment by the line with the error. sample out put is Welcome to Rock Paper Scissors You played: paper Computer played: paper It's a tie Player.h #include<string> using namespace std; class Player{    private:        int play;//variable        public:    string getPlay();//variables    void setPlay(string play);    void setPlay(int play); } string Player = getPlay(){//error    if(this.play == 1){   ...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
c++ Redo Programming Exercise 14 by first sorting the array before determining the array elements that...
c++ Redo Programming Exercise 14 by first sorting the array before determining the array elements that are the sum of two other elements. Use a selection sort algorithm, discussed in this chapter to sort the array. Instructions and code for Programming Exercise 14 have been included for your convenience. Exercise 14 Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are...
> gcc -c lab5.c -lm In file included from lab5.c:8: lab5.h:12: error: expected identifier or ‘(’...
> gcc -c lab5.c -lm In file included from lab5.c:8: lab5.h:12: error: expected identifier or ‘(’ before ‘{’ token > In file included from lab5.c:8: In: Command not found. ]> lab5.h:12: error: expected identifier or ‘(’ before ‘{’ token Too many ('s. > make: *** [lab5.o] Error 1 make:: Too many arguments. #include #include #include #define IN_FILE "lab5.dat" #define OUT_FILE "lab5.txt" /* function prototype */ void find_two_radii (double a, double b, double c, double*radius_inside, double*radius_outside); { *s = 1/2*(a+b+c); *radius_inside...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT