# FAQ: Conditionals & Logic - Review

This community-built FAQ covers the “Review” exercise from the lesson “Conditionals & Logic”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

## Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I did the optional exercise for the review section.
I used a switch statement to calculate the weight on different planets, as seen below(and it works). However when I want to add the statement "your weight in this planet is " std::cout << "Your weight in this planet is " +(weight * rg2); I get an error.
The error is: "invalid operand of char + binary operator
Why is that?

``````int main() {
double weight;
std::cout << "What is your earth weight\n";
std::cin >> weight;
int planet;
std::cout << "Enter number (1-6) for planet to fight on\n";
std::cin >> planet;
switch (planet){
case 1:
{double rg1 = 0.78;
std::cout << (weight * rg1);}
break;
case 2:
{double rg2 = 0.39;
std::cout << (weight * rg2);}
break;
case 3:
{double rg3 = 2.65;
std::cout << (weight * rg3);}
break;
case 4:
{double rg4 = 1.17;
std::cout << (weight * rg4);}
break;
case 5:
{double rg5 = 1.05;
std::cout << (weight * rg5);}
break;
case 6:
{double rg6 = 1.23;
std::cout << (weight *rg6);}
break;
}

``````

Solved
I got it!!!
I was concatenating using “+” instead of " <<" for the standard output!!!
Now my output is how I wanted it “your weight on this planet is ***”

It took me way longer than it should have to figure out why declaring a string failed when compiling…
Strings were mentioned in the earlier lessons, but no examples or details on how to use them were given.
After some googling I found out you have to have “using namespace std;” or use std::string instead of just string when declaring.

Once I finally figured that out, this was my final program.

``````#include <iostream>
using namespace std;

int main() {

double earthWeight;
int planetNumber;
double planetWeight;
string planetName;

std::cin >> earthWeight;

std::cout << "Please select a planet from the following list:\n\n";

std::cout << "   1: Venus\n";
std::cout << "   2: Mars\n";
std::cout << "   3: Jupiter\n";
std::cout << "   4: Saturn\n";
std::cout << "   5: Uranus\n";
std::cout << "   6: Neptune\n\n";

std::cout << "Planet Number: ";
std::cin >> planetNumber;

switch (planetNumber){
case 1 :
planetWeight = earthWeight * 0.78;
planetName = "Venus";
break;
case 2 :
planetWeight = earthWeight * 0.39;
planetName = "Mars";
break;
case 3 :
planetWeight = earthWeight * 2.65;
planetName = "Jupiter";
break;
case 4 :
planetWeight = earthWeight * 1.17;
planetName = "Saturn";
break;
case 5 :
planetWeight = earthWeight * 1.05;
planetName = "Uranus";
break;
case 6 :
planetWeight = earthWeight * 1.23;
planetName = "Neptune";
break;
default :
planetName = "Unknown";
break;
}

if (planetName == "Unknown"){
std::cout << "Invalid planet input.\n";
}else{
std::cout << "Your weight on " << planetName << " would be " << planetWeight << "\n";
}

}
``````
1 Like

//My final program

#include

int main() {
double w = 150;
int p = 8;
std::cout << “What is your earth weight?\n”;
std::cin >> w;
std::cout << “Which plant number will you fight on?\n”;
std::cout << “1. Venus 2. Mars 3. Jupiter 4. Saturn 5. Uranus 6. Neptune \n\n”;
std::cin >> p;

switch § {
case 1 :
std::cout << "Your weight is "<< w0.78 <<“lbs,\n”;
break;
case 2 :
std::cout << "Your weight is " << w
0.39 <<“lbs,\n”;
break;
case 3 :
std::cout << "Your weight is " << w2.65 <<“lbs,\n”;
break;
case 4 :
std::cout << "Your weight is "<< w
1.17 <<“lbs,\n”;
break;
default :
std::cout << "Your weight is "<< w*1.05 <<“lbs,\n”;
break;
}

}

Here’s my solution to the exercise! it works

#include

int main() {
double weight;
std::cout << “Enter your earth weight\n”;
std::cin >> weight;

int planet;
std::cout << “Please, choose a number for the planet you want to fight on\n”;
std::cout << " 1 = Venus\n";
std::cout << " 2 = Mars\n";
std::cout << " 3 = Jupiter\n";
std::cout << " 4 = Saturn\n";
std::cout << " 5 = Uranus\n";
std::cout << " 6 = Neptune\n";
std::cin >> planet;
double v1=0.78;
double m2=0.39;
double j3=2.65;
double s4=1.17;
double u5=1.05;
double n6=1.23;

switch (planet) {
case 1:
std::cout << "Your weight in Venus is " << (weightv1) <<"\n";
break;
case 2:
std::cout << "Your weight in Mars is " << (weight
m2) << “\n”;
break;
case 3:
std::cout << "your weight in Jupiter is " << (weightj3) << “\n”;
break;
case 4:
std::cout << “Your weight in Saturn is” << (weight
s4) << “\n”;
break;
case 5:
std::cout << “Your weight in Uranus is” << (weightu5) << “\n”;
break;
case 6:
std::cout << “Your weight in Neptune is” << (weight
n6) << “\n”;
break;
default:
std::cout << “Error in numbers\n”;

``````  }
``````

}

Here’s mine pretty much as those who choose a similar switch-case solution. Have a good one!

#include
#include <stdlib.h>

int main() {
double weight;
int planet;
std::cout << “Hi champ! what’s your weight in Earth?\n”;
std::cin >> weight;
std::cout << “On which planet is your next fight?\n 1)Venus 2)Mars 3)Jupiter\n 4)Saturn 5)Uranus 6)Neptune\n”;
std::cin >> planet;
// I choose to have a more clean structure with a switch-case flow instead of the if-else if-else
// (which is completely right as an option)
switch(planet) {
case 1: weight = weight / 0.78; std::cout << “Your weight in Venus is:\n” << weight << " kg\n";
break;
case 2: weight = weight / 0.39; std::cout << “Your weight in Mars is:\n” << weight << " kg\n";
break;
case 3: weight = weight * 2.65; std::cout << “Your weight in Jupiter is:\n” << weight << " kg\n";
break;
case 4: weight = weight * 1.17; std::cout << “Your weight in Saturn is:\n” << weight << " kg\n";
break;
case 5: weight = weight * 1.05; std::cout << “Your weight in Uranus is:\n” << weight << " kg\n";
break;
case 6: weight = weight * 1.23; std::cout << “Your weight in Neptune is:\n” << weight << " kg\n";
break;
}
}

This is what I used:

``````#include <iostream>
#include <chrono>

int main() {
int weight;
int planet;
std::cout << "what is your earth weight? ";
std::cin >> weight;
std::cout << "which planet do you want to fight in? ";
std::cin >> planet;
switch (planet) {
case 1:
std::cout << planet / 0.78 << std::endl;
break;
case 2:
std::cout << planet / 0.39 << std::endl;
break;
case 3:
std::cout << planet / 2.65<< std::endl;
break;
case 4:
std::cout << planet / 1.17 << std::endl;
break;
case 5:
std::cout << planet / 1.05 << std::endl;
break;
case 6:
std::cout << planet / 1.23 << std::endl;
break;
default:
std::cout << "Invalid\n";
break;

}

}```
also please make sure to tell us what arithmetic to use :D``````

Guys,why the he** is no (return 0;) needed at the end?!
Cheers for the replies!

Tried to do a fancy work… but I failed…
Here is my code:
#include

int main() {
double EW;
int num;
cart PN;
double FW;
wait
//Variables I defined
std::cout << “Hello warrior!\n”;
std::cout << “This is a programme to help you with calculate the weight of you in different planet only if you answer the following question.\n”;
//Greatings and intros.
std::cout << “1.What is your weight on EARTH?\n”;
std::cin >> EW;
if (EW <= 0){
return;
//In case someone enter a impossible number of weight.
} else {
std::cout >> “Great!”;
}
std::cout << “2.Which planet you want to fight on? Please enter the number of the planet. Here is the number of each planet:\n\n”;
std::cout << " 1. Venus 2. Mars 3. Jupiter\n";
std::cout << " 4. Saturn 5. Uranus 6. Neptune\n\n";
//A tip.
std::cin >> num;
//Enter the number of planet.
switch (num) {
case 1:
FW == EW* 0.78;
PN == “Venus”;
case 2:
FW == EW* 0.39;
PN == “Mars”;
case 3:
FW == EW* 2.56;
PM == “Jupiter”;
case 4:
FW == EW* 1.17;
PN == “Saturn”;
case 5:
FW == EW* 1.05;
PN == “Uranus”;
case 6:
FW == EW* 1.23;
PN == “Neptune”;
default:
std::cout << “We only know about thouse 6 planets right now.”;
return;
//In case user enter a number which is not 1, 2, 3, 4, 5, or 6.
}
std::cout << “So your wight on”;
std::cout >> PN;
std::cout << “is:”;
std::cout >> FW;
std::cout << “\n THX for using this programme!GH & HF!”;
//Final statement
}
I would appreciate if someone can help me!

Compiled and executed using
g++ space.cpp
./a.out
And typed the following code, however the code didn’t run and code academy let me pass?
Any help would be greatly appreciated:

int main() {
double eweight;
std::cout <<“What is your earth weight?\n”;
std::cout <<"My earth weight is ";
std::cin >> eweight;

int num;
std::cout <<“What number planet do you want to fight on?\n”;
/*#, Planet, Relative gravity
1 Venus 0.78
2 Mars 0.39
3 Jupiter 2.65
4 Saturn 1.17
5 Uranus 1.05
6 Neptue 1.23
*/
std::cin >> num;
double pweight;
switch(num){
case 1:
pweight=eweight * 0.78;
break;
case 2:
pweight=eweight * 0.39;
break;
case 3:
pweight=eweight * 2.65;
break;
case 4:
pweight=eweight * 1.17;
break;
case 5:
pweight=eweight * 1.05;
break;
case 6:
pweight=eweight * 1.23;
break;
default:
std::cout <<“Invalid number please try again\n”;
}
std::cout <<“Your planet weight is “<<pweight<<”\n”;

}

Since the main function is a interger(int). Therefore you must return a interger. So imagine if the main function was a string (int main > string main). You have to return a string like

``````return "hello"
``````

or if it was a bool function (int main > bool main). Then the return would be either true or false

``````return true
``````

cheers mate!!
have still a lot to cover

I don’t know why it’s have a lot of “\n” in your HINT
Can you explain to me why is it?
Thanks a lot \

Here is my solution. I decided to use a switch as well - seems like less work?

``````#include <iostream>

int main() {
int earth_weight;
int planet;
double planetary_weight;

std::cout << "Enter your earth weight: \n";
std::cin >> earth_weight;

std::cout << "I have information on the following planets: \n";
std::cout << "1.Venus 2.Mars 3.Jupiter \n";
std::cout << "4.Saturn 5.Uranus 6.Neptune \n";
std::cin >> planet;

switch (planet) {
case 1:
std::cout << "Venus\n";
planetary_weight = earth_weight * .78;
break;
case 2:
std::cout << "Mars\n";
planetary_weight = earth_weight * .39;
break;
case 3:
std::cout << "Jupiter\n";
planetary_weight = earth_weight * 2.65;
break;
case 4:
std::cout << "Saturn\n";
planetary_weight = earth_weight * 1.17;
break;
case 5:
std::cout << "Uranus\n";
planetary_weight = earth_weight * 1.05;
break;
case 6:
std::cout << "Neptune\n";
planetary_weight = earth_weight * 1.23;
break;
default:
std::cout << "Invalid input\n";
}

std::cout << "Your weight on this planet is " << planetary_weight << "\n";
}
``````