954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need some final Touches Help

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 Flight2.cpp (1.52KB)
Robson85
Newbie Poster
11 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

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)'

steveh
Newbie Poster
15 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

It wouldn't let me compile either. One thing I changed which eliminated a lot of errors when I compiled was to make #include instead of #include , 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;
}
};
 
 };
Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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!

1o0oBhP
Posting Pro in Training
445 posts since Dec 2004
Reputation Points: 16
Solved Threads: 6
 

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.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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 Flight_Plan.cpp (3.32KB)
Robson85
Newbie Poster
11 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

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

Attachments Flight_Plan.cpp (3.33KB)
Robson85
Newbie Poster
11 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

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.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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)

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You