Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define CAP 10
#define SEG 10
#define COD 10
#define COST 10
#define PREC 10
struct Discos
{
int op;
int cap[CAP];
int miliseg[SEG];
float cost[COST];
float prec[PREC];
char codven[COD];
};
void ingresar(Dicos& dicos, int& index);
void revisar(Dicos& dicos);
main()
{
int op;
/* int cap[CAP];
int miliseg[SEG];
float cost[COST];
float prec[PREC];
char codven[COD];*/
Discos dicos;
int index;
while( op != 3 ) // If they type 3 the program ends, I can't read spanish so I don't know what your 3 means
{
printf("Programa para capturar datos de la compañia de discos");
printf("\n\nMenu de Opciones: ");
printf("\n1. Ingresar un nuevo articulo al inventario.");
printf("\n2. Revisar los datos del inventario.");
printf("\n3. Salir del programa.");
printf("\n\nFavor de elegir una opcion: ");
scanf("%d", &op);
switch (op)
{
case 1:{
ingresar(dicos, index);
break;
}
case 2:{
revisar();
break;
}
default:{
printf("\n\nOpcion incorrecta.");
break;
}
}
}
return 0;
}
void ingresar(Dicos& dicos, int& index)
{
// int op;
/* int cap[CAP];
int miliseg[SEG];
float cost[COST];
float prec[PREC];
char codven[COD];*/
printf("\nFavor de ingresar los siguientes datos: ");
printf("\n\n\nCapacidad del disco en byte: ");
scanf("%d", &dicos[index].cap);
printf("\nTiempo de acceso en milisegundos: ");
scanf("%d", &dicos[index].miliseg);
printf("\nCodigo del vendedor (A, B, C, D): ");
scanf("%s", &dicos[index].codven);
printf("\nCosto de fabrica: ");
scanf("%f", &dicos[index].cost);
printf("\nPrecio de venta al publico: ");
scanf("%f", &dicos[index].prec);
index++;
return;
}
void revisar(Dicos& dicos)
{
printf("\nDatos del inventario.");
printf("\nCapacidad\tTiempo de acceso\tCodigo del vendedor\tCosto de fabrica\tPrecio de venta");
printf("\n\nDiscos.cap\tDiscos.miliseg\tDiscos.codven\tDiscos.cost\tDiscos.prec");
getch();
return ;
}
You might also want to do something like this. This will ensure that the data is readable from the main function. The variable and index is passed by reference to ingresar.
index will make sure that you can store more than one of the information, since it will show what index in the array to store the data.
I also changed it so it creates your structure and save the data into the structure's members.
Perhaps this might be a little more to what you're looking for? Just be careful - the diacos array has only 10 elements and there's no code to check if you're writing at index 10 or 11 or above, so it can write beyond the end of the array which isn't good.
Just read your reply, and I think it's a little clearer now. You lack the understanding of functions. You call the function, it returns and continues to execute code after that. The loop will make it jump back again unless you select exit.
You still lack a good output function. You may want to do like
Code:
printf(dicos[some_index_here].cost);
Or something. You may need to pass dicos as a reference to the function as well.
I think you're going to have to ask your teacher to properly teach you functions and arguments as well
Borland and VB are two fundamentally different languages.