having difficulty with enum program;need help before midnight

I am recieivng errors and i do not know why, can someone look at my program and explain to me why i get the errors i get?


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
  #include<iostream>
#include<string>
#include<cctype>
#include<iomanip>

using namespace std;

enum planetNames{MERCURY, VENUS, EARTH, MOON, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO};

planetNames findPlanetName(string str);

double calcWeight(planetNames, double);

int main()
{
	double weight;
	double weightOnPlanet;
	string planetName;

	cout << "Planet Names List:\t1. Mercury"
		<< "\t2. Venus\t3. Earth\t4. Moon"
		<< "\t5. Mars\t6. Jupiter\t7. Saturn"
		<< "\t8. Uranus\t9. Neptune"
		<< "\t10. Pluto" << endl;

	cout << "Enter name of the planet:";
	cin >> planetName;
	cout << "enter your weight:";
	cin >> weight;

	weightOnPlanet = calcWeight(findPlanetName(planetName), weight);
	cout << endl << "Weight on planet" << planetName << "is" << weightOnPlanet << "." << endl;

	system("pause");
	return 0;
}

planetNames findPlanetName(string str)
{
	enum planetNames name = EARTH;
	if (str.length() < 4)
	{
		cout << "Invalid planet name..." << endl;
		cout << "Check the spelling Try again" << endl;

		system("pause");
		exit(1);
	}

	switch (toupper(str.at(0)))
	{
	case 'M':
		switch (toupper(str.at(1)))
		{
		case'E':
			name = MERCURY;
			break;
		case'A':
			name = MARS;
			break;
		case'O':
			name = MOON;
			break;
		default:
			cout << "invalid planet name..." << endl << "Check the spelling" << "Try again" << endl;

			system("pause");
			exit(1);
		}
		break;
	case'V':
		name = VENUS;
		break;
	case'E':
		name = EARTH;
		break;
	case'S':
		name = SATURN;
		break;
	case'U':
		name = URANUS;
		break;
	case'N':
		name = NEPTUNE;
		break;
	case'P':
		name = PLUTO;
		break;
	default:
		cout << "Invalid planet name..." << endl;
		cout << "Check the spelling. Try again." << endl;

		system("pause");
		exit(1);
	}

	double calcWeight(planetNames planet, double weight);
	{
		double weightonPlanet = 0;
		switch (planetNames);
		{
		case MERCURY:
			weightonPlanet = weight*0.4155;
			break;
		case VENUS:
			weightonPlanet = weight*0.8975;
			break;
		case EARTH:
			weightonPlanet = weight*1.0;
			break;
		case MOON:
			weightonPlanet = weight*0.166;
			break;
		case MARS:
			weightonPlanet = weight*0.3507;
			break;
		case JUPITER:
			weightonPlanet = weight*2.5374;
			break;
		case SATURN:
			weightonPlanet = weight*1.0677;
			break;
		case URANUS:
			weightonPlanet = weight*0.8947;
			break;
		case NEPTUNE:
			weightonPlanet = weight*1.1794;
			break;
		case PLUTO:
			weightonPlanet = weight*0.899;
			break;
		}

		return weightOnPlanet;
	}




Line 100 should be switch(planet), not switch(planetNames);.

planet is the identifier, planetNames is an enum type.
Also, ditch the semi-colon (;).

Line 97: Remove the semi-colon.

You're also missing a closing brace (}) for the body of your findPlanetName() function. Put a closing brace on line 96.

On line 99 (or line 100 once you've added the previously mentioned closing brace) you've declared and initialized double weightonPlanet = 0;, but later you try to return weightOnPlanet;. C++ is case-sensitive.

Also, congratulations and thank you for making the effort of using code-tags in your first post. Welcome to the forum!
Last edited on
Topic archived. No new replies allowed.