1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
enum epoch { Neogene = 23, Paleogene = 65, Cretaceous = 136, Jurassic = 192, Triassic = 225, Permian = 280,
Carboniferous = 345, Devonian = 395, Silurian = 435, Ordovician = 500, Cambrian = 570, Precambrian = 4500 } ;
const int epoch_end[] = { Neogene, Paleogene, Cretaceous, Jurassic, Triassic, Permian,
Carboniferous, Devonian, Silurian, Ordovician, Cambrian, Precambrian } ;
const int N = sizeof(epoch_end) / sizeof( epoch_end[0] ) ;
const char* const epoch_name[N] = { "Neogene", "Paleogene", "Cretaceous", "Jurassic", "Triassic", "Permian",
"Carboniferous", "Devonian", "Silurian", "Ordovician", "Cambrian", "Precambrian" } ;
int main ()
{
std::cout << "This program will ask a user to input a time in millions of years\n"
"then outputing the period within that year number.\n\n"
"Please enter a starting date\n"
"(For example if you type '23' that means '23,000,000' or 23 million years.\n" ;
int year ;
std::cin >> year ;
int i = 0 ;
while( year > epoch_end[i] ) ++i ; // get to the epoch of the date 'year'
if( i < N ) std::cout << epoch_name[i] << '\n' ;
else std::cout << "before Precambrian\n" ;
// this program accepts one date (in millions of years) and prints out
// the epoch in which that date falls
// TODO: extend this to
// a. let the user enter a range of prehistoric dates (in millions of years)
// b. output the epochs that are included in that range.
// c. put a, b in a loop to allow the user to enter another range
}
|