I am making a lunar lander game, i have made the class and implementation file, but have no idea how to make the altitude reduce by the formular.

Alt = time * velocity

Could you also help me out with how to make time pass through the game, no idea.

Here is the program in order class, implementation and program

// FILE MAGICS.H

#ifndef LUNAR_LANDER
#define LUNAR_LANDER
using namespace std;

class lunar_lander
{
public:
       
   lunar_lander(float, float, float, float, float, float, float);
   
   void setLunar(float alt, float vvel, float tankf, float frate, float massl, float thrust, float fuelconsum);
   

   
    // ALTITUDE AND ACCESSOR
   const float getalt();

   // VERTICAL SPEED AND ACCESSOR
   float vvel();
   const float getvvel();
   
   // FUEL IN TANK AND ACCESSOR
   const float gettankf();
   
   // FUEL FLOW RATE AND ACCESSOR
   float frate(float);
   const float getfrate();
        
   // LANDER MASS AND ACCESSOR
   const float getmassl();
   
   // LANDER THRUST AND ACCESSOR
   const float getthrust();
   
   // MAX FUEL CONSUMPTION RATE AND ACCESSOR
   const float getfuelconsum();
   
   // WHEN LUNAR LANDS
   int landed();
     
   // TIME
   float time(float);
   void time();
   
private:
        
   float alt_;
   int count;
   float vvel_;
   float tankf_;
   float frate_;
   float fuelconsum_;
   float thrust_;
   float massl_;
   float time_;
};
#endif  
   
#include "msam.h"
#include <iostream>
using namespace std;

lunar_lander::lunar_lander(float a, float vs, float fl, float t, float fr, float thr, float ml)
{
   alt_ = a;
   vvel_ = vs; 
   fuelconsum_ = fl;
   tankf_ = t ;
   frate_ = fr;
   thrust_ = thr;
   massl_ = ml;
   
}
void lunar_lander::setLunar(float alt, float vvel, float tankf, float frate, float massl, float thrust, float fuelconsum)
{
     if(alt >0 && alt <1000)
     {
            alt = alt_;
            }
     else
     {
     cerr << "What" << endl;
     }
     
     if( vvel > 0 && vvel <5400)
     {
         vvel = vvel_;
         }
     else
     {
     cerr << "VELOCITY!"<< endl;
     }
     
      if(tankf > 0 && tankf <1700)
     {
         tankf = tankf_;
         }
     else
     {
     cerr << "FULLTANK!"<< endl;
     }
     
     if( frate > 0 && frate <10)
     {
         frate = frate_;
         }
     else
     {
     cerr << "FUELRATE!"<< endl;
     }
     
       if( massl > 0 && massl <900)
     {
         massl = massl_;
         }
     else
     {
     cerr << "LANDERMASS!"<< endl;
     }
     
       if( thrust > 0 && thrust < 10)
     {
         thrust = thrust_;
         }
     else
     {
     cerr << "THRUST!"<< endl;
     }
     
     if( fuelconsum > 0 && fuelconsum < 10)
     {
         fuelconsum = fuelconsum_;
         }
     else
     {
     cerr << "FUELCONSUMPTION!"<< endl;
     }
     }
float lunar_lander::vvel()
{
      return vvel_;
      }
int lunar_lander::landed()
{
   if (alt_<=0)
      return 1;
   return 0;
}
// CORRECTS IF TIME GOES BELOW ZERO
float lunar_lander::time(float q)
{
    time_ = 0.0;
    time_ ++;
    if (time_ <= 0.0)
    {
             time_ = 0.0;
             }
}

void lunar_lander::time()
{
     for(float z = 0.0; z < 5000; ++z)
     time_++;
     }
// RETRIEVES ALTITUDE
const float lunar_lander::getalt()
{
   float qu;
   for(int i = 0; i <1; ++i)
   time_ = i;
   qu = vvel_* time_;
   //qu = time_ * ( thrust_/massl_ - 1.62); 
   frate_ -= (fuelconsum_ * qu);
   alt_ -= qu;
   return alt_;

     }
// SETS INTIAL VALUE OF ALTITUDE
const float lunar_lander::getvvel()
{
       float aw;
   if (tankf_<=0) 
   {
      tankf_=0;
      frate_=0;
   }
   for(int i = 0; i < 1;++i)
   time_++;
   aw = vvel_* time_;
   return aw;
      }  
// SETS INTIAL VALUE OF VELOCITY

const float lunar_lander::gettankf()
{
      return tankf_;
      }
const float lunar_lander::getfrate()
{
      return frate_;
      }
const float lunar_lander::getmassl()
{     
      return massl_;
      }

const float lunar_lander::getthrust()
{
      return thrust_;
       }

const float lunar_lander::getfuelconsum()
{
      return fuelconsum_;
      }
float lunar_lander::frate(float t)
{
  for(float i = 0.0; i < 1; ++i)
   frate_ = t;
  return frate_;
}


   float thrust = 5000;
   float alt = 1000;
   float frate = 0;
   float vvel_ = 5;
   float tankf = 1700;
   const float massl = 900;
   const float fuelconsum = 10;
#include "msam.h"
#include "msam.cpp"
#include <conio.h>
#include <iostream>
using namespace std;

int main()
{
   float throttle;
   float frate_;
   const float time = 10000;
   cout << "Hey, this is starfleet, your orders are to safely land this ship" 
        << " with a " << endl << "velocity greater than " << vvel_
        << "good luck captain "<< endl << endl;
        
   lunar_lander s(1000.0, 0.0, 10.0,900.0,0.0,5000.0,900.0);
   
   while(s.getalt() > 0)
   {
         
   cout <<"Altitude is   " << s.getalt() << endl;
   cout <<"Fuelleft      " << s.getmassl() << endl;
   cout <<"Thrust        " << s.frate(throttle/10) << endl;
   cout <<"Velocity is   " <<s.vvel() << endl;
   
   
   cin >> throttle;
   }
   getch();
}

>> Alt = time * velocity
It should be:
Alt_after_time_t = orig_alt - ( t * velocity )

May be if you clarify what are you trying to achieve, that'll help. If you have some problem statement post that...

Also the code is not compile clean. Update so others don't have to do compiler's work..

----------------------------------------------------------------
Few other things:
----------------------------------------------------------------

for(float z = 0.0; z < 5000; ++z)
     time_++;

When you don't wanna increment in fractions don't use float, use int instead.
----------------------------------------------------------------

float lunar_lander::frate(float t)
{
     for(float i = 0.0; i < 1; ++i)
          frate_ = t;
     return frate_;
}

WHY ?! You can as well just do:

float lunar_lander::frate(float t)
{
     frate_ = t;
     return frate_;
}

----------------------------------------------------------------

// CORRECTS IF TIME GOES BELOW ZERO
float lunar_lander::time(float q)
{
    time_ = 0.0;
    time_ ++;
    if (time_ <= 0.0)
    {
        time_ = 0.0;
    }
}

In the code time_ is never decresed, so how will it go below zero? Also float q is never used.
----------------------------------------------------------------
>> using namespace std;
In general it's not a good idea. Rule of thumb, if you donno why language provides "using namespace", don't use it.
It's definitely a VERY bad idea in header file.
----------------------------------------------------------------

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.