i am doing a C++ program that gets number of vectors, so user can input magnitude of each vector. using 3 functions
1.main function, 2.function that get the number of vectors(looping-number of vector must be positive) and 3.last function get the magnitude of vectors (looping - must be positive) and those input values should returns to the main function for calculation. how do u do that??

``````int main ()
{
int number_vectors;
int vectors;

cout << "VECTOR SUM\n";

for (int count = 0; count <= number_vectors; count ++)
{
cout << "Enter number of vectors: ";
cin >> number_vectors;
number_vectors = get_vectors (vectors);

}
return 0;
}

int get_vectors (int vectors)
{
while (vectors <= 0);
{
cout << "Number must be greater than 0.\n";
}
return (vectors);
}``````

example of input:
Enter number of vectors: 0
number must be greater than 0
Enter number of vectors: 2
enter magnitude of vector 1:
enter magnitude of vector 2:

hey have u been able to do the coding stuff?

hey there ... i am trying to this as well .... here is where i am up to ...

``````#include <iostream>
#include <cmath>
using namespace std;
double pi = 3.14159265358979323846264;
int z =0.0;
double M =0.0;
double D =0.0;
double x;
double y;

int number_of_vectors()
{
int v;
cout << "Enter number of vectors : ";
cin >> v;
while ( v<=0)
{
cout << "Number must be greater than zero.\n";
cout << "Enter number of vectors : ";
cin >> v;
}
z = v;
return z;
}
double magnitude()
{
double m;

for (int n = 1; n <= z; n++)
{
cout <<"Enter magnitude of vector "<< n <<" : ";
cin >> m;
while (m < 0 )
{
cout << "Magnitude cannot be negative\n";
cout <<"Enter magnitude of vector "<< n <<" : ";
cin >> m;
}
M=m;
x = M*cos(pi*D/180);
}
return x;
}

double direction()
{
double d;
for (int n = 1; n<= z; n++)
{
cout <<"Enter direction of vector "<< n <<" : ";
cin >> d;
while (d < - 180 || d > 360)
{
cout <<"Direction must be -180 to + 360\n";
cout <<"Enter direction of vector "<< n <<" : ";
cin >> d;
}
D = d;
y = M*sin(pi*D/180);
}

return D;
}

int main()
{
cout <<"VECTOR SUM\n";
number_of_vectors();
magnitude();
direction();
double m;
double o;
m = sqrt((x*x) + (y*y));
o = atan2(y,x) * 180/pi;
cout << "Total vector :\n";
cout << "magnitude = "<< m <<"\n";
cout << "direction = "<< o <<" degrees.\n";
int k;
cin >>k;
return 0;
}``````

the problem is that i want to sum whatever magnitudes and directions i get from the magnitude and direction functions and a little bit different presentation as i want it to ask for vector 1 magnitude then direction then vector 2 magnitude and direction and so on.... please help

bin2207
i think what you need is up to the end of magnitude function in my coding then you go to the main function and delete everything not related to whatever you need...

Be a part of the DaniWeb community

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