-2
I’m having a hard time printing the result, but before that it’s not realized because it’s a new type created by struct
He doesn’t know because he asks double
follows the code
#include <iostream>
using namespace std;
struct Ponto{
float x;
float y;
float d;
};
void LerRetangulo(Ponto ret[], int tam)
{
for(int i = 0; i<tam;i++)
{
cout <<"digite coordenadas x e y "<<i+1 <<endl;
cin >> ret[i].x>>ret[i].y;
}
}
void CalcDistancia(Ponto ret[], int tam ){
float h
for(int i = 0; i<tam;i++)
{
h = sqrt(pow ( ret[i].x,2) + pow ( ret[i].y,2)); // problema aqui !!!!
}
}
/*
aqui eu estava fazendo alguns teste
void imprimir(?,int tam){
for (int i=0;i<tam;i++){
cout<< "A distancia = "<<? <<endl;
}
*/
}
int main(int argc, char *argv[]) {
Ponto retangulo[4];
LerRetangulo(retangulo,4);
CalcDistancia(retangulo,4);
//imprimir(?,4); duvida aqui !!!!!
return 0;
}
What is this
d
in the structurePonto
? Is it distance? Why would a point have a distance? Do you know that your code doesn’t even compile? It is full of error even syntax, besides being without a pattern. It may sound silly but organizing the code helps you better understand what you’re doing and find silly mistakes. I’ll see if I can answer but I need to know ifd
has any real function in the structure. And what distance should be calculated? Distance between what? Has 4 points. Normally the distance between 2 points is calculated.– Maniero
There are syntax errors, several. You have never tried to compile this program. Answer the rest I asked, there’s no way to solve the problem the way you’re doing. Your code is not solving a plausible problem. So describe the problem, what is the result you want to get. Do you want to calculate the perimeter of a polygon? Why do you need the distance within the point? And if it is the perimeter, what distance do you have to do with it?
– Maniero
@bigown is right, it makes no sense to calculate the distance to a point. The distance is between two points. Anyway, by its description the error is that the function
sqrt
wait for a guydouble
and you’re usingfloat
. Change the guy todouble
in the definition in the structure and test again, please.– Luiz Vieira
It’s no use if you keep making a mistake and leaving others, you need to explain the problem you’re trying to solve. Do you want to calculate the perimeter or do you want to calculate the size of the hypotenuse? In this case you would need to ensure that it is a rectangle.
– Maniero