5 Replies - 543 Views - Last Post: 04 February 2009 - 10:17 PM Rate Topic: -----

#1 champion0369  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 01-February 09

Help with a few errors in a program

Posted 04 February 2009 - 09:25 PM

there is two warnings and a linker error the warnings are from converting a double to an int
the reason i did that is to make sure the output is to two places. i know this can be done in iomanip
but i have forgotten how to do it. if i do figure out how to use iomanip unstead of converting to int and
then back to a double then that will get rid of the two warnings but there is also a linker error and a returned 1
exit status. i dont know why i am getting these errors and would really appreciate it if someone could point out my
mistake.
//Program that uses vectors
//Bryant Harrison
//Dr. Otha Britton
//Csci 222
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

//delaring vector2d struct

struct vector2d
{
	   double xcomponent;
	   double ycomponent;
};

//*****************************************
//function prototypes

vector2d sum(vector2d, vector2d);
double magnitude(vector2d);
vector2d getvector();
void printvector(vector2d);

//**********************************************************************************************************************************************
//Main does this... declares the Vector2D struct and which tests your functions in the following way. 
//Declare two vectors and then use GetVector -- twice, once for each vector -- to obtain the components of the two vectors. 
//Display the two vectors and their magnitudes (use the Magnitude function to calculate the magnitudes and PrintVector to display the vectors!), 
//with appropriate labels. Then use the Sum function to find the Sum of the two vectors and then display the sum with appropriate labels.

int main()
{
	vector2d vector1;
	vector2d vector2;
	vector2d sumvector;
	double vector1mag;
	double vector2mag;
	
	vector1 = getvector();
	vector2 = getvector();
	
	vector1mag = magnitude(vector1);
	vector2mag = magnitude(vector2);
	
	cout << "The magnitude of the vector ";
	printvector(vector1);
	cout << "is " << vector1mag << endl;
	
	cout << "The magnitude of the vector ";
	printvector(vector2);
	cout << "is " << vector2mag << endl;
	
	sumvector = sum(vector1, vector2);
	printvector(sumvector);
	
	system("pause");
	return 0;
}




//*****************************************************
//sum... funciton recieves two vectors and returns the sum of the vectors in the from of another vector
vector2d stempvector1;
vector2d stempvector2;
vector2d ssumvector;

vector2d addvector(vector2d stempvector1, vector2d stempvector2)
{
	   ssumvector.xcomponent = stempvector1.xcomponent + stempvector2.xcomponent;
	   ssumvector.ycomponent = stempvector1.ycomponent + stempvector2.ycomponent;
	   return ssumvector;
}

//********************************************************
//magnitude... function recieves a vector and returns the magnitude
vector2d mtempvector;
double mtemp1;
double mtemp2;
double mxdouble;
double mydouble;
double mmagnitude;
double magnitude(vector2d mtempvector)
{
	   mtemp1 = mtempvector.xcomponent;
	   mtemp2 = mtempvector.ycomponent;
	   mxdouble = mtemp1 * mtemp1;
	   mydouble = mtemp2 * mtemp2;
	   mmagnitude = mxdouble + mydouble;
	   return sqrt(mmagnitude);
}

//***************************************************************
//getvector... function prompts the user for a vector and returns it
double gtempx;
double gtempy;
vector2d gtempvector;
vector2d getvector()
{
		 cout << "Please enter the x cordinate for the vector" << endl;
		 cin >> gtempx;
		 cout << "Please enter the y cordinate for the vector" << endl;
		 cin >> gtempy;
		 gtempvector.xcomponent = gtempx;
		 gtempvector.ycomponent = gtempy;
		 return gtempvector;
}

//***********************************************************************
//printvector... funtion cout's a vector
int pintx;
int pinty;
double pdoublex;
double pdoubley;
vector2d ptempvector;
void printvector(vector2d ptempvector)
{
			  pintx = ptempvector.xcomponent * 100;
			  pinty = ptempvector.ycomponent * 100;
			  pdoublex = pintx / 100;
			  pdoubley = pinty / 100;
			  cout << "The x component of the vector is ";
			  cout << pdoublex << endl;
			  cout << "The y component of the vector is ";
			  cout << pdoubley << endl;
}




Is This A Good Question/Topic? 0
  • +

Replies To: Help with a few errors in a program

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Help with a few errors in a program

Posted 04 February 2009 - 09:35 PM

can you post the error output? like what error it is? It'd be easier to help you that way
Was This Post Helpful? 0
  • +
  • -

#3 champion0369  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 01-February 09

Re: Help with a few errors in a program

Posted 04 February 2009 - 09:41 PM

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Users\Owner\Desktop\lab2.cpp" -o "C:\Users\Owner\Desktop\lab2.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Users\Owner\Desktop\lab2.cpp: In function `void printvector(vector2d)':
C:\Users\Owner\Desktop\lab2.cpp:122: warning: converting to `int' from `double'

C:\Users\Owner\Desktop\lab2.cpp:123: warning: converting to `int' from `double'

oh sorry here it is
C:\Users\Owner\AppData\Local\Temp/cc46baaa.o(.text+0x2cc):lab2.cpp: undefined reference to `sum(vector2d, vector2d)'
collect2: ld returned 1 exit status

Execution terminated
Was This Post Helpful? 0
  • +
  • -

#4 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Help with a few errors in a program

Posted 04 February 2009 - 09:53 PM

undefined reference to `sum(vector2d, vector2d)'

says it all.

you never wrote the function, you only prototyped it and called it.
Was This Post Helpful? 0
  • +
  • -

#5 champion0369  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 01-February 09

Re: Help with a few errors in a program

Posted 04 February 2009 - 10:10 PM

lol yea i definied a vector named addvector and named the vector sum lol thx guys for the help
Was This Post Helpful? 0
  • +
  • -

#6 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Help with a few errors in a program

Posted 04 February 2009 - 10:17 PM

no problem, happy to help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1