Question: Data Types C++ / Receving 'Green' undeclared Identifier I am working on an assignment to Fill in the blank Data Types. I have reread the
Data Types C++ / Receving 'Green' undeclared Identifier
I am working on an assignment to Fill in the blank Data Types. I have reread the small chapters numerous times in "Learn C++ for Game Development" and tried various types but, My issue is calling the color Green from the Enum.
Here is the original code:
// DataTypes.cpp : The data types to declare each of the variables is missing. // Based on the value being stored in the variable and the comments beside it, // fill in the data type at the beginning of each line. Then compile and run // program to make sure you selected the correct types. // // After you submit your answers, try changing the values stored in the // variables. What can you learn about the different data types? // #include "stdafx.h" #include#include using namespace std; int main(int atgc, const char * arg[]) { classAverage = 90.7f; //Decimal number letterScore = 'A'; //Single letter testScore = 95; //Whole number value classTestAverage = 88.4f; //Decimal number, notice the 'f' at the end 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 isStudentPassing = true; //Could be 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; }
Here is what I have completed so far:
#include "stdafx.h" #include#include using namespace std; int main(int atgc, const char * arg[]) { float classAverage = 90.7f; //Decimal number char letterScore = 'A'; //Single letter int testScore = 95; //Whole number value float classTestAverage = 88.4f; //Decimal number, notice the 'f' at the end enum class colorCode { Green = 1, Yellow = 5, Red = 10 }; unsigned int gradebookColor; //Stores list of values colorCode gradebookColor = colorCode::Green; //This line errors out bool isStudentPassing = true; //Could be 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; }
I know I am not understanding how to call the color Green. I have tried various combinations suggested in the book, but nothing seems to work.
Please help so I can fix this and understand why.
Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
