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

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.

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

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)

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.