-1

This is an assignment that i have to have for entry to c++ and I cant wrap my brain around enum. To me it looks like an array but backwards so instead of a number to a value now its a value to a number. Researching around I found it starts at 0 so now im thinking its an array of of some kind?

This issue i believe is what is causeing the confusion i have for the assignment. I got like 95% of it done but the gradebookColor is getting me due to enum.

Only code i can edit or modify must be noted with a comment the professor provided

Note: I dont know if the out put is suppose to be Green or 1

#include <cstdlib>
#include <iostream>
//#include <pch>    //causes errors
using namespace std;```

int main()
{
    double classAverage = 90.7; //Decimal number    use of double due to small decimal_point
    char letterScore = 'A'; //Single letter         use of char due to is be a single string letter
    int testScore = 95; //Whole number value        unknown if could be negative so signed int is used,also is a whole number
    float classTestAverage = 88.4f; //Decimal number, notice the 'f' at the end     use float due to the f
    enum colorCode {
        Green = 1,
        Yellow = 5,
        Red = 10
    };gradebookColor; //Stores list of values

    gradebookColor = Green; //This line does not need a declaration, it was declared in the line above

    bool isStudentPassing = true; //Could be true or false  bool deals only in true or false

    cout << "The class average is currently "
        << classAverage
        << endl;
    cout << "The class test average was "
        << classTestAverage
        << endl;
    cout << "Your test score was "
        << testScore
        << endl;
    cout << "Your current letter score is "
        << letterScore
        << endl;
    cout << "The color of your gradebook entry is "
        << gradebookColor
        << endl;
    cout << "Are you passing? "
        << boolalpha        //This line allows the word 'true' or 'false' to be printed instead of '0' or '1'
        << isStudentPassing
        << endl;
    return 0;
}
  • Does this answer your question? [What is the difference between array and enum in C ?](https://stackoverflow.com/questions/31801828/what-is-the-difference-between-array-and-enum-in-c) – Joseph Sible-Reinstate Monica Jul 05 '21 at 16:58
  • I see immediately ``` on line 4, and an invalid semicolon in `};gradebookColor;` How did these creep in? Please tidy your code up so that it exhibits the problem you are trying to solve. – TonyK Jul 05 '21 at 17:14

1 Answers1

0

an enum is not an array. It is a bundled list of named constant variables. For instance, in your example, it lets you choose the color from three different choices: Green, Yellow, or Red. This way, you can define

colorCode gradebookColor = Green;

instead of, e. g.

int gradebookColor = 1;

which is much less descriptive.

It is not mandatory that your enum starts with a 0, as you can see in the example provided where no value is equal to 0. But the first default value is a 0, if no other is specified. So, the enum above is basically the same as

typedef int colorType;

const colorType Green = 1;
const colorType Yellow = 5;
const colorType Red = 10;
CasualCay
  • 45
  • 5