c++

closed account (j8qkSL3A)
Can someone solve the one errors I am getting:
_______________________________________________________________________

2DVector.cxx:20:10: error: variable has incomplete type 'Vector'
Vector vec;
_____________________________________________________________________ ^


#include <iostream>
#include <stdlib.h>

using namespace std;

struct Vector;

int magnitude;
float angle;



// Given an input vector vec, compute the magnitude and angle and put them in
// *magnitude and *angle.
void calculateMagAndAngle(const Vector &vec, double *magnitude, double *angle);


int main()
{
Vector vec;

GetMagnitude(&vec.magnitude);
GetAngle(&vec.angle);

cout << "\n\nThe vector you entered\n\n" << "Magnitude: " << vec.magnitude << "\tAngle: " << vec.angle << "\n\n";

system("pause");
return 0;
}

void GetMagnitude(int *magnitude)
{
cout << "Magnitude: ";
cin >> *magnitude;
}

void GetAngle(float *angle)
{
cout << "Angle: ";
cin >> *angle;
}


Last edited on
You don't have a full definition of Vector in this code.

A full definition would look something like this:

1
2
3
4
struct Vector{
    double magnitude;
    double angle;
};
closed account (j8qkSL3A)
Am I replacing


struct Vector;

int magnitude;
float angle;



to the following:



struct Vector{
double magnitude;
double angle;
};


closed account (j8qkSL3A)
this gave me three errors.
this gave me three errors.

That means you found other errors with your program. It is common to fix one error and have several more pop up after. I am pretty sure what they are simply based on the change you made, and without looking at your code.

Someone would probably be more willing to help better if you post the errors and use code tags for your code.
Last edited on
'GetMagnitude': identifier not found
'GetAngle': identifier not found

You don't have prototypes for these two functions so you need to move main function below all functions or to write prototypes.


'GetMagnitude' cannot convert parameter 1 from 'double *' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
'GetAngle' : cannot convert parameter 1 from 'double *' to 'float *'

According to the
void calculateMagAndAngle(const Vector &vec, double *magnitude, double *angle);

magnitude and angle should be doubles, but they are int and float in your functions respectively. Correct code is:
1
2
void GetMagnitude(double *magnitude)
void GetAngle(double *angle)

Last edited on
Topic archived. No new replies allowed.