Sunday, March 31, 2013



Weight Calculation Code For any Planet:

Problem statement:
Write a program that determines your weight on another planet. The program should ask for the user’s weight on Earth, and then present a menu of other planets in our solar systems. The user should use one of the planets from the menu and use a switch statement to calculate the weight on the chosen planet. Use the factors given below for the other planets. Save program as planets.cpp
Planets
Multiply by
Planets
Multiply by
Mercury
0.37
Saturn
1.15
Venus
0.88
Uranus
1.15
Mars
0.38
Neptune
1.12
Jupiter
2.64
Pluto
0.04

Program:
#include<iostream>
using namespace std;
void planet(int, float);
int main()
{
       int n;
       float mass;
       cout<<"enter mass on Earth";
       cin>>mass;
       cout<<"Chose a planet";
       cout<<"\n1\tMercury\n2\tVenus\n3\tMars\n4\tJupiter\n5\tSaturn\n6\tUrance\n7\tNeptune\n8\tPluto";
       cin>>n;
       planet(n, mass);
       return 0;
}
void planet(int x, float m)
{
       switch(x)
       {
       case 1:
              cout<<"\nwaight on Mercury="<<m*0.37;
              break;
       case 2:
              cout<<"\nmass on venus="<<m*0.88;
              break;
       case 3:
              cout<<"\nmass on Mars="<<m*0.38;
              break;
       case 4:
              cout<<"\nmass on Jupiter="<<m*2.64;
              break;
       case 5:
              cout<<"\nmass on Saturn="<<m*1.15;
              break;
       case 6:
              cout<<"\nmass on Urance="<<m*1.15;
              break;
       case 7:
              cout<<"\nmass on Neptune="<<m*1.12;
              break;
       case 8:
              cout<<"\nmass on Pluto="<<m*.04;
              break;
       default:
              cout<<"what is this sack?";
       }
}


Output:

No comments:

Post a Comment