This is our assignmenWrite 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 classet

THis is what I have so far. How do i fix it? Im so lost Im getting 3 errors, and cant seem to fix them.

#include <iostream>
using std::cout;
using std::endl;


double y2m=1.09361329834;
double m2y=0.9144;

int main ()
{
int i;
double yards, meters;

for (i=5; i<=100; i=i+5)
{
	double yards= getyards(i);
cout << i << yards << endl;
;}
for (i=5; i<=100; i=i+5)

double getmeters(i,&meters);
cout << i << meters <<endl;
;}

double yards(int x)
{
return (x*m2y)
;}

Recommended Answers

All 11 Replies

what are the error messages ? My guess is that you failed to prototype the functions before using them. You need to add function declarations near the top of your program, such as about line 7.

c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(14) : error C3861: 'getyards': identifier not found
c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(17) : error C2078: too many initializers
c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(17) : error C2440: 'initializing' : cannot convert from 'double *__w64 ' to 'double'


these are the errorsim getting. i cant fix the first for some reason and have never seen the last 2. im very new to computer programming.

You have syntax problems.

line #16: get rid of the word "double" --you are not declaring a new variable (you've already declared "yards" above).

line #21: same kind of problem. Replace the word "double" with "meters".

Move your yards() function (lines 5..28) above main() (to line 8). Rename the yards() function to getyards().

You are missing a function named getmeters().

[EDIT] Also, you shouldn't be using &meters. And your second for loop is missing { and }.

Good luck.

You have syntax problems.

line #16: get rid of the word "double" --you are not declaring a new variable (you've already declared "yards" above).

line #21: same kind of problem. Replace the word "double" with "meters".

Move your yards() function (lines 5..28) above main() (to line 8). Rename the yards() function to getyards().

You are missing a function named getmeters().

[EDIT] Also, you shouldn't be using &meters. And your second for loop is missing { and }.

Good luck.

Now Im really lost.

where do i put these?
Move your yards() function (lines 5..28) above main() (to line 8). Rename the yards() function to getyards().

You are missing a function named getmeters().


I have changed this so far. SAme errors though

#include <iostream>
using std::cout;
using std::endl; 


double y2m=1.09361329834;
double m2y=0.9144; 

int main ()
{
int i;
double yards, meters; 

for (i=5; i<=100; i=i+5)
{	
	
yards= getyards(i);

	cout << i << yards << endl;;}
for (i=5; i<=100; i=i+5) 

meters getmeters(i,&meters);
cout << i << meters <<endl;
;} 
double yards(int x)
{return (x*m2y);
}

Am i At least on the right track?

fix the error messages on at a time, then recompile after each fix. For example the first one says error C3861: 'getyards': identifier not found. That means the compiler does not know what getyards is on line 17. But look on line 25 -- you gave it the wrong function name, and need to rename it to getyards. Then you have to either move the function from line 25 to line 7 or on line 7 prototype the function. This is the prototype you should put on line 7 if you don't want to move the function from line 25 to line 7.

double getyards(int);

Another problem you have: don't attempt to write so much code before compiling because (1) the program you posted is just filled with syntax errors, and (2) you will get fludded with compile errors that take ten times as long to fix. You should only write two or three lines before compiling. Fix all errors and warnings, then write a few more lines of code.

Now I get these errors.

c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(19) : error C2078: too many initializers
c:\documents and settings\owner\my documents\visual studio 2005\projects\damel_7\damel_7\conversions.cpp(19) : error C2440: 'initializing' : cannot convert from 'double *__w64 ' to 'double'


how do i change the number of initializers. and what is the second error. I have never seen it. thanks

please repost your current code. And use code tags this time.

#include <iostream>
using std::cout;
using std::endl;  

double y2m=1.09361329834;
double m2y=0.9144; 
double getyards(int);

int main ()
{
	int i;
	double yards, meters; 
	for (i=5; i<=100; i=i+5)
	{	
		double yards= getyards(i);
		cout << i << yards << endl;
		;}
	for (i=5; i<=100; i=i+5) 
	double getmeters(i,&meters);
	cout << i << meters <<endl;
	;} 
double getyards (int x)
{return 
(x*m2y)
;}

this is what i have... Im really lost now. I keep getting those errors

I know this is a lot to ask, but this assignment is due tonight and i cannot for the life of me figure out how to change it. and i cannot get it to compile if any one has any insight, it would really be very appreciated.

Stop using the type double everytime you reference a variable. Once you say double varname you only need to use varname from that point on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.