I am working on an assignment to Fill in the blank Data Types. I have reread the
ID: 3837541 • Letter: I
Question
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:
//
#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:
// 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[])
{
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
******** gradebookColor = Green; //This line does not accept anything I tried.
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 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:
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.