Finished Code. Can someone verify that is it working?

Feb 23, 2011 at 3:32am
It's my first code. I put alot of effort into it. I just haven't been able to see if it actually works because tomorrow I go the the computer lab to test it. Positive and negative feedback is welcomed. Also, here is a link to the description of what the code is suppose to have.
Link: http://pdfcast.org/pdf/assignment

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
#include<iostream>
#include<cmath>
using namespace std;

int CheckWeight(int weight, string Planet);

int main()
{
int weight,res;
string planetName;

do{
cout << "Please enter your weight" <<endl;
cin >> weight;}
while(cin.good()==false);
cout << " " << endl;
do{ 
cout << "Please enter a planet name from the following list" << endl;
cout << "Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto" << endl;
cin >> planetName;
cout << " " << endl;
// Call function to check weight
res = CheckWeight(weight, planetName);
}while(res==1);
system("PAUSE");
return 0;
}// end main()

// Function for calculating weight

int CheckWeight(int weight, string Planet)
{
int Result=0;
if(Planet== "Mercury"){
cout << "Your weight on Mercury is " << (weight*0.4155)<< endl;
}
else if(Planet== "Venus"){
cout << "Your weight on Venus is " << (weight*0.8975)<< endl;
}
else if(Planet== "Earth"){
cout << "Your weight on Earth is " << (weight*1.0)<< endl;
}
else if(Planet== "Moon"){
cout << "Your weight on Moon is " << (weight*0.166)<< endl;
}
else if(Planet== "Mars"){
cout << "Your weight on Mars is " << (weight*0.3507)<< endl;
}
else if(Planet== "Jupiter"){
cout << "Your weight on Jupiter is " << (weight*2.5374)<< endl;
}
else if(Planet== "Saturn"){
cout << "Your weight on Saturn is " << (weight*1.0677)<< endl;
}
else if(Planet== "Uranus"){
cout << "Your weight on Uranus is " << (weight*0.8947)<< endl;
}
else if(Planet== "Neptune"){
cout << "Your weight on Neptune is " << (weight*1.1794)<< endl;
}
else if(Planet== "Pluto"){
cout << "Your weight on Pluto is " << (weight*0.0899)<< endl;
}
else{
cout << "You entered a wrong planet name. Please try again " << endl;
cout << " " << endl;
Result=1;
}
return Result;
}
Feb 23, 2011 at 4:06am
You need to #include "stdlib.h" to get system() to work. Other than that, works perfectly on my machine, good job!
Feb 23, 2011 at 5:36am
You should change that giant if, else if, else statement to a switch statement.

@rocketboy9000
No... never tell someone they did a good job if they used a system() command...
Last edited on Feb 23, 2011 at 5:37am
Feb 23, 2011 at 5:49am
You should change that giant if, else if, else statement to a switch statement.


Erm, you can't use a switch-case on non-integral types. >_>
Feb 23, 2011 at 5:59am
Your long if else seems to work fine, you could make it dynamic though, you know, because technically pluto isn't a planet and there are more planets than those in our solar system. o

Oh and "your weight on moon" isn't it "The Moon"? Which begs the question... why isn't it "the mercury", "the venus", or "the mars"? The Earth and The Moon are important to us, but why prepend them with "The"?

aaaaaaanyways, you could make a "planet" class and a "planets" class to hold a vector of "planet"'s =)

edit: harsh packetpirate... harsh, oh and you don't have to make the planet class, especially since this is an assignment. I think it'd be cool anyways =)
Last edited on Feb 23, 2011 at 6:01am
Feb 24, 2011 at 7:11pm
because all the other names are Latin, I prefer "Terra" and "Luna".
Feb 24, 2011 at 8:36pm
ahhh thanks for quenching my lust for the knowledge of the planets =)
Last edited on Feb 24, 2011 at 8:36pm
Topic archived. No new replies allowed.