| | |
Need some final Touches Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 11
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
Solved Threads: 6
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.
C++ Syntax (Toggle Plain Text)
#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; } }; };
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!
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! http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
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:
You have to make the output look a little neater though, it was all scrunched up together.
C++ Syntax (Toggle Plain Text)
#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; } } }; } };
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
Solved Threads: 6
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Range Of Long??
- Next Thread: Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





