Good morning. I have a problem with a code that I am doing for a project in c ++, which I need to search in a structure, in which I use pointers, a specific data. In this case it is the name of a metro or train station. I have tried several things, but none of them have happened and the answers I have seen on the internet are structures which do not use pointers, and I need to use pointers in this project.
What I have is the following:
#include <iostream>
using namespace std;
int main (){
struct datosEstacion{
char nombre[30];
int km;
int precio;
char nombre2[30];
int km2;
int precio2;
char nombre3[30];
int km3;
int precio3;
char nombre4[30];
int km4;
int precio4;
char nombre5[30];
int km5;
int precio5;
char nombre6[30];
int km6;
int precio6;
};
struct datosEstacion *linea1;
linea1=(struct datosEstacion*)malloc(sizeof(struct datosEstacion));
strcpy (linea1->nombre,"Propatria");
linea1->km=0;
linea1->precio=0;
strcpy (linea1->nombre2,"Agua salud");
linea1->km2=14;
linea1->precio2=500;
strcpy (linea1->nombre3,"La hoyada");
linea1->km3=21;
linea1->precio3=1000;
strcpy (linea1->nombre4,"Bellas Artes");
linea1->km4=29;
linea1->precio4=1500;
strcpy (linea1->nombre5,"Colegio de ingenieros");
linea1->km5=35;
linea1->precio5=2000;
strcpy (linea1->nombre6,"Plaza Venezuela");
linea1->km6=44;
linea1->precio6=2500;
cout<<"***Estaciones del metro de la linea 1***"<<endl;
cout<<"Nombre:"<<linea1->nombre<<endl;
cout<<"Kms:"<<linea1->km<<endl;
cout<<"Precio:"<<linea1->precio<<endl;
cout<<endl;
cout<<"Nombre:"<<linea1->nombre2<<endl;
cout<<"Kms:"<<linea1->km2<<endl;
cout<<"Precio:"<<linea1->precio2<<endl;
cout<<endl;
cout<<"Nombre:"<<linea1->nombre3<<endl;
cout<<"Kms:"<<linea1->km3<<endl;
cout<<"Precio:"<<linea1->precio3<<endl;
cout<<endl;
cout<<"Nombre:"<<linea1->nombre4<<endl;
cout<<"Kms:"<<linea1->km4<<endl;
cout<<"Precio:"<<linea1->precio4<<endl;
cout<<endl;
cout<<"Nombre:"<<linea1->nombre5<<endl;
cout<<"Kms:"<<linea1->km5<<endl;
cout<<"Precio:"<<linea1->precio5<<endl;
cout<<endl;
cout<<"Nombre:"<<linea1->nombre6<<endl;
cout<<"Kms:"<<linea1->km6<<endl;
cout<<"Precio:"<<linea1->precio6<<endl;
cout<<endl;
cout<<endl;
string estacion1;
string estacion2;
cout<<"Ingrese la estacion uno (punto de partida)"<<endl;
getline(cin,estacion1);
cout<<"Ingrese la estacion dos (punto de llegada)"<<endl;
getline(cin,estacion2);
//aqui se supone es donde va la sentencia que busca "el nombre de la estacion, para luego "juntarlo" con sus otros datos, que son los kms y el precio
free(linea1);
system("pause");
}
I had tried if (station1) == (line1) but it does not work for me or work for me. The thing is that I do not want to store any data (I already have them pre-established), but I look for it in the structure of pointers or structure with pointers. What I'm looking for is that, after the user enters the name of the station, this is linked with the kms and the price, then print the total that will pay and certain other conditions. I would appreciate your answers.