So I'm asking you. Why should this program use an enum? It does not make sense to me, since we have to assign a value to each period. Is there a different/better way of using it than what I have done here? And would it be more efficient to use more functions as the instructions say:
//create a function that determines the period corresponding to a date
//create another function that returns the string corresponding to
//each identifier for the enum
//use a for loop to output the series of periods in the range
Also, did I get my calculations right, on the dates? It's B.C. so it's kinda backward.

Did I put the enum in the right spot? I'd prefer it not to be global, but could not get it to work otherwise.

Yes, I know you should not use system("Pause") but that is what all of my instructors have preferred, so far. At least I'm finally getting the hang of not using so many global variables, and learning how to clean up my main()

If there's anything else you see that could/should have been done better, please tell me! ♥
//Chapter 10 Homework //Problem 3, Page 517, Textbook //Due Date: 19/Apr #include <iostream> using namespace std; enum dates { Quaternary = int(2.5), Tertiary = 65, Cretaceous = 136, Jurassic = 192, Triassic = 225, Permian = 280, Carboniferous = 345, Devonian = 395, Silurian = 435, Ordovician = 500, Cambrian = 570, Precambrian = 4500 }; //get beginning year int getBegYr(int begYr) { cout<<"\nEnter a range of prehistoric dates (in millions of years), and I\n"; cout<<"will tell you which periods are included within that range.\n\n"; cout<<"Enter beginning year: "; cin>>begYr; return begYr; } //get ending year int getEndYr(int endYr) { cout<<"Enter ending year: "; cin>>endYr; return endYr; } bool errorCheck(int begYr, int endYr) { //make sure begYr > endYr because the dates are B.C. if(begYr<=endYr) { cout<<"The ending year must be less than the beginning year,\n\n"; return true; } return false; } //determine & print results void printPeriods(int begYr, int endYr) { cout<<"\nPeriods included within that range: \n"; if(endYr <= Quaternary) { cout<<"Quaternary\n"; } if(endYr <= Tertiary && begYr > Quaternary) { cout<<"Tertiary\n"; } if(endYr <= Cretaceous && begYr > Tertiary) { cout<<"Cretaceous\n"; } if(endYr <= Jurassic && begYr > Cretaceous) { cout<<"Jurassic\n"; } if(endYr <= Triassic && begYr > Jurassic) { cout<<"Triassic\n"; } if(endYr <= Permian && begYr > Triassic) { cout<<"Permian\n"; } if(endYr <= Carboniferous && begYr > Permian) { cout<<"Carboniferous\n"; } if(endYr <= Devonian && begYr > Carboniferous) { cout<<"Devonian\n"; } if(endYr <= Silurian && begYr > Devonian) { cout<<"Silurian\n"; } if(endYr <= Ordovician && begYr > Silurian) { cout<<"Ordovician\n"; } if(endYr <= Cambrian && begYr > Ordovician) { cout<<"Cambrian\n"; } if(begYr >= Precambrian) { cout<<"Precambrian\n"; } } int main () { char quit = 'Y'; while(quit != 'N') { bool flag = true; int begYr = 0, endYr = 0; while (flag) { begYr = getBegYr(begYr); endYr = getEndYr(endYr); flag = errorCheck(begYr, endYr); } //confirm input data cout<<begYr<<" to " <<endYr<<endl; printPeriods(begYr, endYr); cout<<"\nWould you like to continue? Y/N: "; cin>>quit; quit = toupper(quit); } system("pause"); return 0; }
This post has been edited by OliveOyl3471: 18 April 2009 - 09:40 AM