Advertisement
karlakmkj

Practice - if-else if-else statement

Mar 25th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. /*
  2. Program to check weight on different planets using if-else if-else statement.
  3.  
  4. Compile and execute using:
  5. g++ space.cpp
  6. ./a.out
  7.  
  8. */
  9. #include <iostream>
  10.  
  11. int main() {
  12.   double weight;
  13.   int plat;
  14.  
  15.   std::cout << "Enter your earth weight: ";
  16.   std::cin >> weight;
  17.  
  18.   std::cout << "\nChoose the planet number that you wanna fight on:  \n\n";
  19.   std::cout << "1. Mercury\n 2. Venus\n 3. Mars\n 4. Jupiter\n 5. Saturn\n 6. Uranus\n 7. Neptune\n";
  20.   std::cin >> plat; //remember to store input into variable!!
  21.  
  22.   if (plat == 1 ){
  23.     weight *= 0.38;
  24.   }
  25.   else if (plat == 2){
  26.     weight *= 0.91;
  27.   }
  28.   else if (plat == 3){
  29.     weight *= 0.38;
  30.   }
  31.   else if (plat == 4){
  32.     weight *= 2.34;
  33.   }
  34.   else if (plat == 5){
  35.     weight *= 1.06;
  36.   }
  37.   else if (plat == 6){
  38.     weight *= 0.92;
  39.   }
  40.   else if (plat == 7){
  41.     weight *= 1.19;
  42.   }
  43.  
  44. std::cout << "Your weight would be: " <<  weight << "\n";
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement