Hi

Iv'e almost completed this programme built for calculating a pilots fuel consumption on various flight distances. I have done most of it at college and now tried to execute it at home and there is an error. I am unsure whether it is just that my compiler is a different version from the colleges or if something in the code is wrong.

Could someone please have a little look. Much appreciated
Rob

Attachments
#include <iostream.h>
#include <stdlib.h>

int main()
{

int fuel, mean;
float flight_time,dist,ascent_time,ascent_fuel,alt,level_time,descent_fuel,
descent_time,level_flight,total_fuel,level_fuel,m,f;

void get_fuel ( int &f, int &m, float alt);


get_fuel (fuel, mean,alt);

cout<<"fuel consumed"<<fuel;
cout<<"mean fuel consumed"<<mean;
cout<<"enter distance";
cin>>dist;

flight_time = dist/300;
cout<<flight_time;

ascent_time = (alt/1000)/60;
cout<<"the ascent time is"<<ascent_time;

descent_time = (alt/1000)/60;
cout<<"the decent time is"<<descent_time;

level_time = flight_time -(ascent_time+descent_time);
cout<<"the level out time is"<<level_time;

descent_fuel = mean* descent_time*0.9;
cout<<"Fuel consumption for descent was"<<descent_fuel;

ascent_fuel = mean* ascent_time*1.4;
cout<<"Fuel consumption for ascent was"<<ascent_fuel;

level_fuel = fuel* level_time;
cout<<"Fuel consumption for level flight"<<level_fuel;

total_fuel = ascent_fuel + level_fuel;
cout<<"The total fuel consumption is "<<total_fuel;

 system("PAUSE");
 return 0;


};


void get_fuel(float&f,float&m,float alt)
{
cout<<"what Altitude";
cin>> alt;

if (alt== 5000)
{
f=680;
m=814;
}
if (alt == 10.000);
{
f=615;
m=750;
{
if (alt == 15000);
{
f=545;
m=680;
}
if(alt == 20000);
{
f = 475;
m = 615;
}
if(alt == 25000);
{
f=410;
m=545;
}
if (alt == 30000);
{
f=340;
m=475;
}

if (alt == 35000);
{
f=270;
m=410;
}

}

if (alt ==40000)
{
f=200;
m=475;
}
};



 };

if (alt == 10.000); is incorrect (as far as logic).
I usually use Visual C++ 6.0 but had Dev C++ handy, it gives the following error:
[Linker error] undefined reference to `get_fuel(int&, int&, float)'

It wouldn't let me compile either. One thing I changed which eliminated a lot of errors when I compiled was to make #include <iostream> instead of #include <iostream.h>, and adding using namespace std; right before the main program code. After that all I got was a linker error. I also changed what robson said.

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int fuel, mean;
float flight_time,dist,ascent_time,ascent_fuel,alt,level_time,descent_fuel,
descent_time,level_flight,total_fuel,level_fuel,m,f;
void get_fuel ( int &f, int &m, float alt);

get_fuel (fuel, mean,alt);
cout<<"fuel consumed"<<fuel;
cout<<"mean fuel consumed"<<mean;
cout<<"enter distance";
cin>>dist;
flight_time = dist/300;
cout<<flight_time;
ascent_time = (alt/1000)/60;
cout<<"the ascent time is"<<ascent_time;
descent_time = (alt/1000)/60;
cout<<"the decent time is"<<descent_time;
level_time = flight_time -(ascent_time+descent_time);
cout<<"the level out time is"<<level_time;
descent_fuel = mean* descent_time*0.9;
cout<<"Fuel consumption for descent was"<<descent_fuel;
ascent_fuel = mean* ascent_time*1.4;
cout<<"Fuel consumption for ascent was"<<ascent_fuel;
level_fuel = fuel* level_time;
cout<<"Fuel consumption for level flight"<<level_fuel;
total_fuel = ascent_fuel + level_fuel;
cout<<"The total fuel consumption is "<<total_fuel;
 system("PAUSE");
 return 0;

};

void get_fuel(float&f,float&m,float alt)
{
cout<<"what Altitude";
cin>> alt;
if (alt== 5000)
{
f=680;
m=814;
}
if (alt == 10000);
{
f=615;
m=750;
{
if (alt == 15000);
{
f=545;
m=680;
}
if(alt == 20000);
{
f = 475;
m = 615;
}
if(alt == 25000);
{
f=410;
m=545;
}
if (alt == 30000);
{
f=340;
m=475;
}
if (alt == 35000);
{
f=270;
m=410;
}
}
if (alt ==40000)
{
f=200;
m=475;
}
};
 
 };

edit to my previous post (at the end): change robson to steveh

I also realized that you didn't make a function prototype for get_fuel(). You have to put the prototype before the using namespace std; I think.

get_fuel is defined for float parameters but you are passing ints. Thats th linker error
There also seems to be a stray }; at the end (function blocks DONT need a ;). Consider using a switch statement to replace all the IF statements, it reads easier in some cases saves vertical space!

Well I found a way. For some reason it wouldn't compile unless i made a new block at then end with nothing in it, but it worked. Here it is:

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
float fuel, mean;
float flight_time,dist,ascent_time,ascent_fuel,alt,level_time,descent_fuel,
descent_time,level_flight,total_fuel,level_fuel,m,f;
void get_fuel ( float&f, float&m, float alt);
get_fuel (fuel, mean, alt);
cout<<"fuel consumed"<<fuel;
cout<<"mean fuel consumed"<<mean;
cout<<"enter distance";
cin>>dist;
flight_time = dist/300;
cout<<flight_time;
ascent_time = (alt/1000)/60;
cout<<"the ascent time is"<<ascent_time;
descent_time = (alt/1000)/60;
cout<<"the decent time is"<<descent_time;
level_time = flight_time -(ascent_time+descent_time);
cout<<"the level out time is"<<level_time;
descent_fuel = mean* descent_time*0.9;
cout<<"Fuel consumption for descent was"<<descent_fuel;
ascent_fuel = mean* ascent_time*1.4;
cout<<"Fuel consumption for ascent was"<<ascent_fuel;
level_fuel = fuel* level_time;
cout<<"Fuel consumption for level flight"<<level_fuel;
total_fuel = ascent_fuel + level_fuel;
cout<<"The total fuel consumption is "<<total_fuel;
 system("PAUSE");
 return 0;

};

void get_fuel(float&f, float&m, float alt)
{
	cout<<"What Altitude";
	cin>> alt;
	{
		if (alt== 5000)
				{
				  f=680;
				  m=814;
				}
		if (alt == 10000)
				{
				  f=615;
				  m=750;
				{
		if (alt == 15000)
				{
				  f=545;
				  m=680;
				}
		if(alt == 20000)
				{
				  f=475;
				  m=615;
				}
		if(alt == 25000)
				{
				  f=410;
				  m=545;
				}
		if (alt == 30000)
				{
				  f=340;
				  m=475;
				}
		if (alt == 35000)
				{
				  f=270;
				  m=410;
				}
		if (alt ==40000)
				{
				  f=200;
				  m=475;
				}
	}	
};			  
}
};

You have to make the output look a little neater though, it was all scrunched up together.

Ok iv'e totally changed it as i couldn't get it to work and started from scratch. Thanks for your help. Any chance you could look at this 1. It contains errors which i cannot identify.

Thanks so much.

Attachments
#include <iostream.h>
#include <stdlib.h>

int main()
{

//global variables

char rep;
float fuel_con, level_fc, f_n, mean_alt, ascent_des_fuel;
float descent_time, ascent_time, flight_time, level_time, ascent_fc, descent_fc,
 alt;

      do
      {
      fuel_con=0;
      level_fc=0;
      alt=0;
      descent_time=0;
      ascent_time=0;
      flight_time=0;
      level_time=0;
      ascent_fc=0;
      descent_fc=0;
      f_n=0;
      ascent_des_fuel=0;
      mean_alt=0;

      system ("cls");

      //setting prototypes
      void time (float &ft);
      void altitude_fc (float &al, float &fc);

      cout <<"Flight Plan Calculator"<<"\n";

//calling functions
altitude_fc (alt, fuel_con);
time (flight_time);

//Calculations

ascent_time = (alt / 1000);
descent_time = (alt / 1000);
mean_alt = alt / 2;

level_time - flight_time - (ascent_time + descent_time);

level_fc = flight_time + fuel_con;
ascent_fc = 1.4 * (fuel_con * flight_time);
descent_fc = 0.9 * (fuel_con * flight_time);
f_n = descent_fc + ascent_fc + descent_fc;

/*cout <<"the flight time is:";
       cout <<flight_time<<"\n";

       cout <<"the descent time is: ";
       cout <<descent_time<<"\n";

       cout <<"the ascent time is: ";
       cout <<ascent_time<<"\n";

       cout <<"the level flight time is: ";
       cout <<level_time<<"\n";

       cout <<"the ascent fuel consumption is: ";
       cout <<ascent_fc<<"\n";

       cout <<"the descent fuel consumption is: ";
       cout <<descent_fc<<"\n";

       cout <<"the level flight consumption is: ";
       cout <<level_fc<<"\n";

       cout <<"the mean altitude is: ";
       cout <<mean_alt<<"\n";*/

       cout <<"total fuel needed: ";
       cout <<f_n<<"\n";

       cout <<"get new calculation: ";
         cin >>rep;

 while (rep=='y' || rep=='y');

      system("PAUSE");
      return 0;
}

//defining first function
void altitude_fc (float &al, float &fc)
{

//local variables
int sel;

sel=0;

      cout <<"  Altitude           Fuel Consumtpion"<<"\n";
      cout <<"1:  0                       750      "<<"\n";
      cout <<"2: 5000                     680      "<<"\n";
      cout <<"3:10000                     615      "<<"\n";
      cout <<"4:15000                     545      "<<"\n";
      cout <<"5:20000                     475      "<<"\n";
      cout <<"6:25000                     410      "<<"\n";
      cout <<"7:30000                     340      "<<"\n";
      cout <<"8:35000                     270      "<<"\n";
      cout <<"9:40000                     200      "<<"\n";

      cout <<"Make your selection [1 - 9]: ";
      cin>>sel;
      cout<<"\n";

switch (sel)
       {
       case 1 : (al=0) + (fc=750); break;
       case 2 : (al=5000) + (fc=680); break;
       case 3 : (al=10000) + (fc=615) ; break;
       case 4 : (al=15000) + (fc=545) ; break;
       case 5 : (al=20000) + (fc=475) ; break;
       case 6 : (al=25000) + (fc=410) ; break;
       case 7 : (al=30000) + (fc=340) ; break;
       case 8 : (al=35000) + (fc=270) ; break;
       case 9 : (al=40000) + (fc=200) ; break;
       }
};
//defining second function
void time (float &ft)
     {
//local variables
float dis;
dis=0;

cout <<"Enter flight distance: ";
cin >>dis;
cout <<"\n";

ft = 300 / dis;
};

Hi, all sorted now. Finnally i have a programme that works! Yesss. Iv'e attached just incase you want to see it.

Attachments
#include <iostream.h>
#include <stdlib.h>

int main()
{

//global variables

char rep;
float fuel_con, level_fc, f_n, mean_alt, ascent_des_fuel;
float descent_time, ascent_time, flight_time, level_time, ascent_fc, descent_fc,
 alt;

      do
      {
      fuel_con=0;
      level_fc=0;
      alt=0;
      descent_time=0;
      ascent_time=0;
      flight_time=0;
      level_time=0;
      ascent_fc=0;
      descent_fc=0;
      f_n=0;
      ascent_des_fuel=0;
      mean_alt=0;

      system ("cls");

      //setting prototypes
      void time (float &ft);
      void altitude_fc (float & al, float & fc);

      cout <<"Flight Plan Calculator"<<"\n";

//calling functions
altitude_fc (alt, fuel_con);
time (flight_time);

//Calculations

ascent_time = (alt / 1000);
descent_time = (alt / 1000);
mean_alt = alt / 2;

level_time - flight_time - (ascent_time + descent_time);

level_fc = flight_time + fuel_con;
ascent_fc = 1.4 * (fuel_con * flight_time);
descent_fc = 0.9 * (fuel_con * flight_time);
f_n = descent_fc + ascent_fc + descent_fc;

/*cout <<"the flight time is:";
       cout <<flight_time<<"\n";

       cout <<"the descent time is: ";
       cout <<descent_time<<"\n";

       cout <<"the ascent time is: ";
       cout <<ascent_time<<"\n";

       cout <<"the level flight time is: ";
       cout <<level_time<<"\n";

       cout <<"the ascent fuel consumption is: ";
       cout <<ascent_fc<<"\n";

       cout <<"the descent fuel consumption is: ";
       cout <<descent_fc<<"\n";

       cout <<"the level flight consumption is: ";
       cout <<level_fc<<"\n";

       cout <<"the mean altitude is: ";
       cout <<mean_alt<<"\n";*/

       cout <<"total fuel needed: ";
       cout <<f_n<<"\n";

       cout <<"get new calculation: ";
         cin >>rep;
         }
 while (rep=='y' || rep=='y');

      system("PAUSE");
      return 0;
}

//defining first function
void altitude_fc (float & al, float & fc)
{

//local variables
int sel;

sel=0;

      cout <<"  Altitude           Fuel Consumtpion"<<"\n";
      cout <<"1:  0                       750      "<<"\n";
      cout <<"2: 5000                     680      "<<"\n";
      cout <<"3:10000                     615      "<<"\n";
      cout <<"4:15000                     545      "<<"\n";
      cout <<"5:20000                     475      "<<"\n";
      cout <<"6:25000                     410      "<<"\n";
      cout <<"7:30000                     340      "<<"\n";
      cout <<"8:35000                     270      "<<"\n";
      cout <<"9:40000                     200      "<<"\n";

      cout <<"Make your selection [1 - 9]: ";
      cin>>sel;
      cout<<"\n";

switch (sel)
       {
       case 1 : (al=0) + (fc=750); break;
       case 2 : (al=5000) + (fc=680); break;
       case 3 : (al=10000) + (fc=615) ; break;
       case 4 : (al=15000) + (fc=545) ; break;
       case 5 : (al=20000) + (fc=475) ; break;
       case 6 : (al=25000) + (fc=410) ; break;
       case 7 : (al=30000) + (fc=340) ; break;
       case 8 : (al=35000) + (fc=270) ; break;
       case 9 : (al=40000) + (fc=200) ; break;
       }
};
//defining second function
void time (float &ft)
     {
//local variables
float dis;
dis=0;

cout <<"Enter flight distance: ";
cin >>dis;
cout <<"\n";

ft = 300 / dis;
};

Nice job, One thing i noticed, was that you use iostream.h, and actually I think that is the old version. The new one is just iostream. on newer compilers iostream.h will come up as an error. But in order to use iostream you have to put using namespace std; when using things like cout and cin etc... Just a suggestion though.

also you should test your program before you hand it in. One thing i found was that when your selecting an altitude you can submit any thing you want, and it will output data. Just something you should look for when you programs are done (actual finishing touches)

This article has been dead for over six months. Start a new discussion instead.