Data Types C++ / Receving \'Green\' undeclared Identifier I am working on an ass
ID: 3837789 • Letter: D
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 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:
Here is what I have completed so far:
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.
Explanation / Answer
Here is the fixed 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 <cstdlib>
#include <iostream>
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 colorCode {
Green = 1,
Yellow = 5,
Red = 10
} gradebookColor; //Stores list of values
gradebookColor = 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;
}
basically you don't need keyword clas with enum
also gradebookColor is not unsigned int and your were declaring it twice, once as unsigned int and then as colorCode.