>>how can i increase the enum type to go from freshman to sophemore etc.
with the assignment operator: x = sophmore;
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
if the enums have consecutive integral values (as in this case), we can increment by adding one to the value.
#include <iostream>
int main()
{
enum level { FRESHMAN=0, SOPHMORE=1, JUNIOR=2, SENIOR=3 } ;
const char* const literal_level[] =
{ "FRESHMAN", "SOPHMORE", "JUNIOR", "SENIOR" } ;
for( level lev = FRESHMAN ; lev <= SENIOR ; lev = level(lev+1) )
std::cout << literal_level[ lev ] << '\n' ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
>>lev = level(lev+1)
Ah yes -- but lev++ will not compile.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343