Skip to content

Commit 7730f25

Browse files
updated code and fixed an issue
1 parent 4c3f496 commit 7730f25

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

weight_Calculator/.DS_Store

6 KB
Binary file not shown.

weight_Calculator/a.out

24.5 KB
Binary file not shown.

weight_Calculator/terminal_notes.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.

weight_Calculator/weight_calculator

24.5 KB
Binary file not shown.
Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,62 @@
1+
//©Alexander Haislip, Wednesday March 27th 2020
12
#include <iostream>
23
#include <string>
34
using namespace std;
45

6+
// Function that calculates your weight on another planet
7+
double calc(double earthWeight, double rel) {
8+
return earthWeight * rel;
9+
}
10+
511
int main() {
612

713
double planet_Weight;
814
double earth_Weight;
9-
double calc = earth_Weight * planet_Weight;
1015

16+
//This will take input from the user asking their current earth weight.
1117
cout << "What is your weight on earth? LBS : ";
12-
cin.clear();//you need to clear the flags before input
13-
getline (cin, earth_Weight);
14-
18+
cin >> earth_Weight;
1519

16-
std::cout << "Choose a relative gravity for the planet in which you want to know your weight on : Planet Relative Gravity Earth = 1 , Venus = 0.78 , Mars = 0.39 , Jupiter = 2.65 , Saturn = 1.17 , Uranus = 1.05 , Neptune = 1.23: \n";
17-
cin.clear();//you need to clear the flags before input
18-
getline (cin, planet_Weight);
20+
int planet;
21+
std::cout << "Choose a planet in which you want to know your weight on :\n";
22+
std::cout << "Mars => 1\nVenus => 2\nJupiter => 3\nSaturn => 4\nUranus => 5\nNeptune => 6\n";
23+
cin >> planet;
1924

25+
double planetMultiplier;
26+
string planetName;
2027

21-
if (planet_Weight == 1) {
22-
cout << "Your weight on Earth is... " << calc;
23-
} else if (planet_Weight == 0.39) {
24-
cout << "Your weight on Mars is... " << calc;
25-
} else if (planet_Weight == 0.78) {
26-
cout << "Your weight on Venus is... " << calc;
27-
} else if (planet_Weight == 2.65) {
28-
cout << "Your weight on Jupiter is... " << calc;
29-
} else if (planet_Weight == 1.17) {
30-
cout << "Your weight on Saturn is... " << calc;
31-
} else if (planet_Weight == 1.05) {
32-
cout << "Your weight on Uranus is... " << calc;
33-
} else if (planet_Weight == 1.23) {
34-
cout << "Your weight on Neptune is... " << calc;
35-
} else {
36-
37-
cout << "Your weight on this planet is Unknown... ";
38-
39-
28+
switch(planet) {
29+
case 1 : // Mars
30+
planetMultiplier = 0.78;
31+
planetName = "Mars";
32+
break;
33+
case 2 : // Venus
34+
planetMultiplier = 2.65;
35+
planetName = "Venus";
36+
break;
37+
case 3 : // Jupiter
38+
planetMultiplier = 1.17;
39+
planetName = "Jupiter";
40+
break;
41+
case 4 : // Saturn
42+
planetMultiplier = 1.05;
43+
planetName = "Saturn";
44+
break;
45+
case 5 : // Uranus
46+
planetMultiplier = 1.23;
47+
planetName = "Uranus";
48+
break;
49+
case 6 : // Neptune
50+
planetMultiplier = 0.17;
51+
planetName = "Neptune";
52+
break;
53+
54+
4055
}
41-
56+
57+
double newWeight = calc(earth_Weight, planetMultiplier);
58+
cout << "Your weight on " << planetName << " is " << newWeight << endl;
59+
4260
}
61+
62+

0 commit comments

Comments
 (0)