Need some final Touches Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 11
Reputation: Robson85 is an unknown quantity at this point 
Solved Threads: 0
Robson85 Robson85 is offline Offline
Newbie Poster

Need some final Touches Help

 
0
  #1
Jan 24th, 2005
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, 6 views)
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 15
Reputation: steveh is an unknown quantity at this point 
Solved Threads: 0
steveh steveh is offline Offline
Newbie Poster

Re: Need some final Touches Help

 
0
  #2
Jan 25th, 2005
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)'
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Need some final Touches Help

 
0
  #3
Jan 25th, 2005
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.

  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. };
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Need some final Touches Help

 
0
  #4
Jan 25th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Need some final Touches Help

 
0
  #5
Jan 25th, 2005
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!
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Need some final Touches Help

 
0
  #6
Jan 26th, 2005
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 11
Reputation: Robson85 is an unknown quantity at this point 
Solved Threads: 0
Robson85 Robson85 is offline Offline
Newbie Poster

Re: Need some final Touches Help

 
0
  #7
Jan 26th, 2005
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, 1 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 11
Reputation: Robson85 is an unknown quantity at this point 
Solved Threads: 0
Robson85 Robson85 is offline Offline
Newbie Poster

Re: Need some final Touches Help

 
0
  #8
Jan 26th, 2005
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, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Need some final Touches Help

 
0
  #9
Jan 26th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Need some final Touches Help

 
0
  #10
Jan 27th, 2005
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)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC