solved

Hello. I am a beginner needing assistance. Below are the instructions, code, and errors.

You are taking a geology class, and the professor wants you to write a program to help students learn the periods of geologic time. The program should let the user enter a range of prehistoric dates (in millions of years), and then output the periods that are included in that range. Each time this output is done, the user is asked if he or she wants to continue. The goal of the exercise is for the student to try to figure out when each period began, so that he or she can make a chart of geologic time.

Within the program, represent the periods with an enumeration type made up of their names. You will probably want to create a function that determines the period corresponding to a date, and another function that returns the string corresponding to each identifier in the enumeration. Then you can use a For loop to output the series of periods in the range. The periods of geologic time are given here:

Period Name Starting Date (millions of years)
Neogene 23
Paleogene 65
Cretaceous 136
Jurassic 192
Triassic 225
Permian 280
Carboniferous 345
Devonian 395
Silurian 435
Ordovician 500
Cambrian 570
Precambrian 4500 or earlier

Use functional decomposition to solve this problem. Be sure to use good coding style and documenting comments. The prompts and error messages that are output should be clear and informative.

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  
//Write a program to help students learn the periods  of geologic time.


#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

//declare enum

enum PeriodName {NEOGENE, PALEOGENE, CRETACEOUS,JURASSIC,
				TRIASSIC,PERMIAN,CARBONIFEROUS,DEVONIAN,
				SILURIAN,ORDOVICIAN,CAMBRIAN,PRECAMBRIAN};

//funtion declarations

int toInt(PeriodName);
string toString(PeriodName);

int main()
{
	PeriodName name;
	char ch= 'y';
	int range1, range2;

//loop
	while (ch=='y' || ch=='Y')
	{
//user prompt to enter year ranges
		cout<<"Enter the range of the prehistoric dates"
			<<endl<<"(in Million years, seperated"
			<<"by space):";
//read years
		cin>>range1>>range2;
//check validity of range then display error
		if(range1<0||range2<0)
			cout<<"Invalid range. Please try again."<<endl;
		else
		{
//display
			cout<<endl<<"Period Name\tStarting Date"
				<<endl<<"___________\t___________"
				<<"_"<<endl;
//loop to display peroid names within range
			for(name=NEOGENE; name<=PRECAMBRIAN;
				name=PeriodName(name+1))
			{
				if(toInt(name)>=range1 &&
					toInt(name)<range2)
					cout<<toString(name)<<"\t\t"
					<<toInt(name)<<endl;
			}
			cout<<endl;
//prompt user to continue
			cout<<"Do you want to continue?"
				<<"(Press 'n' to Exit):";
			cin>>ch;
			cout<<endl;
		}
	}
	system("Pause");
	return 0;
}
// function that returns the starting date/interger
int toInt(PeriodName name);
}
int startingYear;
//switch case
switch(name)
{
case PRECAMBRIAN:
	startingYear=4500;
	break;
case CAMBRIAN:
	startingYear=570;
	break;
case ORDOVICIAN:
	startingYear=500;
	break;
case SILURIAN:
	startingYear=435;
	break;
case DEVONIAN:
	startingYear=395;
	break;
case CARBONIFEROUS:
	startingYear=345;
	break;
case PERMIAN:
	startingYear=280;
	break;
case TRIASSIC:
	startingYear=225;
	break;
case JURASSIC:
	startingYear=192;
	break;
case CRETACEOUS:
	startingYear=136;
	break;
case PALEOGENE:
	startingYear=65;
	break;
case NEOGENE:
	startingYear=23;
	break;
}
return startingYear;
}
//function that returns the timeperiod as a string
string toString(PeriodName name)
{
string periodName;
//switch case to return name based on parameter
switch(name)
{
case PRECAMBRIAN:
	periodName="Precambrian";
	break;
case CAMBRIAN:
	periodName="Cambrian";
	break;
case ORDOVICIAN:
	periodName="Ordovician";
	break;
case SILURIAN:
	periodName="Silurian";
	break;
case DEVONIAN:
	periodName="Devonian";
	break;
case CARBONIFEROUS:
	periodName="Carboniferous";
	break;
case PERMIAN:
	periodName="Permian";
	break;
case TRIASSIC:
	periodName="Triassic";
	break;
case JURASSIC:
	periodName="Jurassic";
	break;
case CRETACEOUS:
	periodName="Cretaceous";
	break;
case PALEOGENE:
	periodName="Paleogene";
	break;
case NEOGENE:
	periodName="Neogene";
	break;
}
return periodName;
}


 


error displays:
7:1: error: expected declaration before '}' token
Last edited on
Double post: http://www.cplusplus.com/forum/beginner/162465/

This does not belong on this subforum. Multi-posting doesn't increase the chance that someone will help you, rather it decreases it.

-Albatross
solved
Last edited on
Topic archived. No new replies allowed.