C++ meters to yards.

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

Join Date: Oct 2007
Posts: 17
Reputation: towhoe260 is an unknown quantity at this point 
Solved Threads: 0
towhoe260 towhoe260 is offline Offline
Newbie Poster

C++ meters to yards.

 
0
  #1
Nov 17th, 2007
This is my assignment.
Write a program to convert between yards and meters. Your solution must utilize functions to perform the conversions. Your functions must meet these requirements:

One of the functions must use pass-by-value, returning the converted measure
One of the functions must use pass-by-reference to store its result (the function does not have a return value).
Your program must create two tables - one showing the yards equivalent to meter measures from 0 yards to 100 yards (by 5 yard increments: 0, 5, 10, . . . , 100) and the other showing meters equivalent to yards measures 0 through 100 (by 5 meter increments: 0, 5, 10, ... , 100). Original measures are all integer values. Calculated measures are to be displayed accurate to two decimal places.
The output for both tables must fit on one default screen (79 columns by 23 rows), so your tables will need to be organized into multiple columns. Everything must be lined up nicely and the tables neatly and informatively labeled. This assignment can be done with a single file. It is not necessary to define any classes.

I have gotten this code written, but im getting these errors. Im at a loss for fixing them

Compiling...
Conversions.cpp
c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(21) : error C2440: '=' : cannot convert from 'double (__cdecl *)(void)' to 'double'
There is no context in which this conversion is possible
c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(22) : error C2660: 'getmeters' : function does not take 2 arguments
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\damel_7\damel_7\Debug\BuildLog.htm"
damel_7 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. double y2m=1.09361329834;
  6. double m2y=0.9144;
  7. double getyards(int);
  8. double getmeters();
  9.  
  10. int main (void)
  11. {
  12. int i;
  13. double yards, meters;
  14. for (i=5; i<=100; i=i+5)
  15. {
  16. double yards = getyards(i);
  17. cout << i << yards << endl;
  18. ;}
  19. for (i=5; i<=100; i=i+5)
  20.  
  21. meters=getmeters;
  22. getmeters(i,meters);
  23.  
  24. cout << i << &meters <<endl;
  25. ;}
  26. double getyards (int x)
  27. {
  28. return
  29. (x*m2y)
  30. ;}
Last edited by Ancient Dragon; Nov 17th, 2007 at 10:38 pm. Reason: added line numbers
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: C++ meters to yards.

 
0
  #2
Nov 17th, 2007
line 21 and line 22 are wrong.
First implement the function getmeters.
Indentation of the code is horrible. Write the getmeters function and repost code.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: C++ meters to yards.

 
0
  #3
Nov 17th, 2007
line 21: meters is a double, getmeters is a function. you can not assign a function to a double. But what you can do is assign the return value of the function to a double like this: meters=getmeters();
line 22: delete that line because it has wrong parameters (see function prototype on line 8) and doesn't do anything.

line 24: why are you printing the address of meters instead of its value ?

pay closer attention to the open and closing braces { and } -- they must match. For every { there must be a corresponding }. Don't be so careless in your coding.
Last edited by Ancient Dragon; Nov 17th, 2007 at 10:44 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: towhoe260 is an unknown quantity at this point 
Solved Threads: 0
towhoe260 towhoe260 is offline Offline
Newbie Poster

Re: C++ meters to yards.

 
0
  #4
Nov 17th, 2007
I dont know how to do that. please give me something to go on. is there a site i can look up or something. Our book is horrible.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: C++ meters to yards.

 
0
  #5
Nov 17th, 2007
>>I dont know how to do that.
you don't know how to do what? I reformatted your code in another thread for free, I'm not going to do it again every time you post something. Go back to your other thread and see how I formatted it. Also read the information in the link that someone else posted. If you are not going to read the responses to the threads then there is not much we can do for you.

>>please give me something to go on
I did. learn to read the threads.

>>Our book is horrible
Maybe, but you have to read it.
Last edited by Ancient Dragon; Nov 17th, 2007 at 10:50 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: towhoe260 is an unknown quantity at this point 
Solved Threads: 0
towhoe260 towhoe260 is offline Offline
Newbie Poster

Re: C++ meters to yards.

 
0
  #6
Nov 17th, 2007
This is what i have so far, and im gettiing even more errors and warnings. Im about ready to give up. Ive been working on this program for 4 days, with absolutley no luck
these are the errors im getting now. which i have never seen.

Conversions.obj : error LNK2019: unresolved external symbol "double __cdecl getmeters(void)" (?getmeters@@YANXZ) referenced in function _main
C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\damel_7\Debug\damel_7.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\damel_7\damel_7\Debug\BuildLog.htm"
damel_7 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. double y2m=1.09361329834;
  6. double m2y=0.9144;
  7. double getyards(int);
  8. double getmeters();
  9.  
  10. int main ()
  11. {
  12. int i;
  13. double yards, meters;
  14. for (i=5; i<=100; i=i+5)
  15. {
  16. double yards = getyards(i);
  17. cout << i << yards << endl;
  18. ;}
  19. for (i=5; i<=100; i=i+5)
  20.  
  21. meters=getmeters();
  22.  
  23. cout << i << &meters <<endl;
  24. ;}
  25. double getyards (int x)
  26. {
  27. return
  28. (x*m2y)
  29. ;}
Last edited by Ancient Dragon; Nov 17th, 2007 at 11:14 pm. Reason: corrected code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: towhoe260 is an unknown quantity at this point 
Solved Threads: 0
towhoe260 towhoe260 is offline Offline
Newbie Poster

Re: C++ meters to yards.

 
0
  #7
Nov 17th, 2007
I attempted to do everything you told me to. Im lost, with worst errors than I had prior. Sorry I didnt format right. I didnt know how. and i just learned how to read pm's. sorry
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: C++ meters to yards.

 
0
  #8
Nov 17th, 2007
>>Sorry I didnt format right. I didnt know how
Here is a short tutorial on how to format your program. You should probably bookmark it so that you can refer to it often until you have it down in your head.

>>error LNK2019: unresolved external symbol "double __cdecl getmeters(void)" (?getmeters@@YANXZ) referenced in function _main

That error message is telling you that the compiler can not find a function named getmeters that does not have any parameters. You prototyped it ok on line 8 and called it on line 21, but nowhere did you actually write that function.
Last edited by Ancient Dragon; Nov 17th, 2007 at 11:13 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: towhoe260 is an unknown quantity at this point 
Solved Threads: 0
towhoe260 towhoe260 is offline Offline
Newbie Poster

Re: C++ meters to yards.

 
0
  #9
Nov 17th, 2007
I didnt know how to format for the website.

Could you please help me with my program? I did what you said, and im still not getting anything to work

I dont know how to write the function for it, everything ive tried comes up with an error?
Last edited by towhoe260; Nov 17th, 2007 at 11:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: C++ meters to yards.

 
0
  #10
Nov 17th, 2007
using code tags here is pretty simple,
[code=c++]
// your code goes here
[/code]


And don't use tabs in your code because they will not look right when posted here even though they may look ok on your computer screen. Depending on what compiler you are using the compiler may have option to replace tabs with spaces. If not, then just hit the space bar on your keyboard instead of the tab key.

>>I dont know how to write the function for it, everything ive tried comes up with an error
post what you tried.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC