944,161 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2564
  • C++ RSS
Jan 24th, 2005
0

Need some final Touches Help

Expand Post »
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
Attached Files
File Type: cpp Flight2.cpp (1.5 KB, 20 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Robson85 is offline Offline
11 posts
since Jan 2005
Jan 25th, 2005
0

Re: Need some final Touches Help

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)'
Reputation Points: 10
Solved Threads: 0
Newbie Poster
steveh is offline Offline
15 posts
since Nov 2004
Jan 25th, 2005
0

Re: Need some final Touches Help

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)
  1.  
  2. #include <iostream>
  3. #include <stdlib.h>
  4. using namespace std;
  5. int main()
  6. {
  7. int fuel, mean;
  8. float flight_time,dist,ascent_time,ascent_fuel,alt,level_time,descent_fuel,
  9. descent_time,level_flight,total_fuel,level_fuel,m,f;
  10. void get_fuel ( int &f, int &m, float alt);
  11.  
  12. get_fuel (fuel, mean,alt);
  13. cout<<"fuel consumed"<<fuel;
  14. cout<<"mean fuel consumed"<<mean;
  15. cout<<"enter distance";
  16. cin>>dist;
  17. flight_time = dist/300;
  18. cout<<flight_time;
  19. ascent_time = (alt/1000)/60;
  20. cout<<"the ascent time is"<<ascent_time;
  21. descent_time = (alt/1000)/60;
  22. cout<<"the decent time is"<<descent_time;
  23. level_time = flight_time -(ascent_time+descent_time);
  24. cout<<"the level out time is"<<level_time;
  25. descent_fuel = mean* descent_time*0.9;
  26. cout<<"Fuel consumption for descent was"<<descent_fuel;
  27. ascent_fuel = mean* ascent_time*1.4;
  28. cout<<"Fuel consumption for ascent was"<<ascent_fuel;
  29. level_fuel = fuel* level_time;
  30. cout<<"Fuel consumption for level flight"<<level_fuel;
  31. total_fuel = ascent_fuel + level_fuel;
  32. cout<<"The total fuel consumption is "<<total_fuel;
  33. system("PAUSE");
  34. return 0;
  35.  
  36. };
  37.  
  38. void get_fuel(float&f,float&m,float alt)
  39. {
  40. cout<<"what Altitude";
  41. cin>> alt;
  42. if (alt== 5000)
  43. {
  44. f=680;
  45. m=814;
  46. }
  47. if (alt == 10000);
  48. {
  49. f=615;
  50. m=750;
  51. {
  52. if (alt == 15000);
  53. {
  54. f=545;
  55. m=680;
  56. }
  57. if(alt == 20000);
  58. {
  59. f = 475;
  60. m = 615;
  61. }
  62. if(alt == 25000);
  63. {
  64. f=410;
  65. m=545;
  66. }
  67. if (alt == 30000);
  68. {
  69. f=340;
  70. m=475;
  71. }
  72. if (alt == 35000);
  73. {
  74. f=270;
  75. m=410;
  76. }
  77. }
  78. if (alt ==40000)
  79. {
  80. f=200;
  81. m=475;
  82. }
  83. };
  84.  
  85. };
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Jan 25th, 2005
0

Re: Need some final Touches Help

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.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Jan 25th, 2005
0

Re: Need some final Touches Help

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!
Reputation Points: 16
Solved Threads: 6
Posting Pro in Training
1o0oBhP is offline Offline
445 posts
since Dec 2004
Jan 26th, 2005
0

Re: Need some final Touches Help

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:

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include <iostream>
  3. #include <stdlib.h>
  4. using namespace std;
  5. int main()
  6. {
  7. float fuel, mean;
  8. float flight_time,dist,ascent_time,ascent_fuel,alt,level_time,descent_fuel,
  9. descent_time,level_flight,total_fuel,level_fuel,m,f;
  10. void get_fuel ( float&f, float&m, float alt);
  11. get_fuel (fuel, mean, alt);
  12. cout<<"fuel consumed"<<fuel;
  13. cout<<"mean fuel consumed"<<mean;
  14. cout<<"enter distance";
  15. cin>>dist;
  16. flight_time = dist/300;
  17. cout<<flight_time;
  18. ascent_time = (alt/1000)/60;
  19. cout<<"the ascent time is"<<ascent_time;
  20. descent_time = (alt/1000)/60;
  21. cout<<"the decent time is"<<descent_time;
  22. level_time = flight_time -(ascent_time+descent_time);
  23. cout<<"the level out time is"<<level_time;
  24. descent_fuel = mean* descent_time*0.9;
  25. cout<<"Fuel consumption for descent was"<<descent_fuel;
  26. ascent_fuel = mean* ascent_time*1.4;
  27. cout<<"Fuel consumption for ascent was"<<ascent_fuel;
  28. level_fuel = fuel* level_time;
  29. cout<<"Fuel consumption for level flight"<<level_fuel;
  30. total_fuel = ascent_fuel + level_fuel;
  31. cout<<"The total fuel consumption is "<<total_fuel;
  32. system("PAUSE");
  33. return 0;
  34.  
  35. };
  36.  
  37. void get_fuel(float&f, float&m, float alt)
  38. {
  39. cout<<"What Altitude";
  40. cin>> alt;
  41. {
  42. if (alt== 5000)
  43. {
  44. f=680;
  45. m=814;
  46. }
  47. if (alt == 10000)
  48. {
  49. f=615;
  50. m=750;
  51. {
  52. if (alt == 15000)
  53. {
  54. f=545;
  55. m=680;
  56. }
  57. if(alt == 20000)
  58. {
  59. f=475;
  60. m=615;
  61. }
  62. if(alt == 25000)
  63. {
  64. f=410;
  65. m=545;
  66. }
  67. if (alt == 30000)
  68. {
  69. f=340;
  70. m=475;
  71. }
  72. if (alt == 35000)
  73. {
  74. f=270;
  75. m=410;
  76. }
  77. if (alt ==40000)
  78. {
  79. f=200;
  80. m=475;
  81. }
  82. }
  83. };
  84. }
  85. };
You have to make the output look a little neater though, it was all scrunched up together.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Jan 26th, 2005
0

Re: Need some final Touches Help

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.
Attached Files
File Type: cpp Flight Plan.cpp (3.3 KB, 14 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Robson85 is offline Offline
11 posts
since Jan 2005
Jan 26th, 2005
0

Re: Need some final Touches Help

Hi, all sorted now. Finnally i have a programme that works! Yesss. Iv'e attached just incase you want to see it.
Attached Files
File Type: cpp Flight Plan.cpp (3.3 KB, 15 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Robson85 is offline Offline
11 posts
since Jan 2005
Jan 26th, 2005
0

Re: Need some final Touches Help

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.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Jan 27th, 2005
0

Re: Need some final Touches Help

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)
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Range Of Long??
Next Thread in C++ Forum Timeline: Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC