I'm currently working on a small c++ project and I use it as practice for a final exam, so this could be a silly error. So... the thing is, I declared an array of structs for using it as a shopping list, were "articulo" (means article or product) has a name and a quantity field. Then declared that "articulo" struct like a list of them called "ListaArticulos" (means list of products) which has a maximum of 100 products. My question is, where am I messing this thing up? I mean, I tried to store values inside the struct and then saving them into the array and I keep getting the: expected primary expression before '.' token in line "cin >> articulo.prod;" and "cin >> articulo.cant;" .
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
typedef struct
{
char prod[30];
int cant;
}articulo;
typedef articulo ListaArticulos[100];
int nElem,opc;
int main()
{
while( opc!=3 ){
cout << "Bienvenido al la lista!." << "\n";
cout << "\n[1]. Agregar articulos a la lista.";
//cout << "\n[2]. Ver articulos actuales.";
//cout << "\n[3]. Salir del programa." << "\n";
cout << "\nElija una opción para continuar: ";
cin >> opc;
switch(opc)
{
default:
cout << "\nCuantos articulos?: ";
cin >> nElem;
ListaArticulos LA;
for(int i=0; i<nElem; i++){
cout << "Ingrese articulo " << i++ << ": ";
cin >> articulo.prod;
cout << "Ingrese cantidad: ";
cin >> articulo.cant;
LA[i] = articulo;
}
break;
}
}
return 0;
}
Any tips on this would be appreciate. Thank you all!