I am new to C++ and started learning it just for fun. I am using a C++ course in Codecademy I wrote the program below but unable to compile it. I keep getting the error "Else without a previous else if"...
#include <iostream>
int main() {
double earthw = 0;
double planet = 0;
double weight = 0;
//Ask and receive earth weight
std::cout << "What is your earth weight? \n";
std::cin >> earthw;
//Ask which planet to figth on
std::cout << "Which Planet Would you like to fight in? \n";
//List all planets
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";
//Receive planet number
std::cin >> planet;
//Calculations and inputing weight on specific planet
if (planet == 1) {
weight = earthw * 0.78;
}
else if (planet == 2) {
weight = earthw * 0.39;
}
else if (planet == 3) {
weight = earthw * 2.65;
}
else if (planet == 4) {
weight = earthw * 1.17;
}
else if (planet == 5) {
weight = earthw * 1.05;
}
else if (planet == 6) {
weight = earthw * 1.23;
}
std::cout << "Your weight is: " << weight << "Kg\n";
}