Advertisement
gonzalob

Untitled

Nov 11th, 2021
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct item{
  5.  
  6.     char nombre[50];
  7.     float precio;
  8.     int id;
  9.     int cantidad;
  10. }item;
  11.  
  12. void mostrarArreglo(item carrito[4]);
  13. void cargarArreglo(item carrito[4]);
  14.  
  15. int main()
  16. {
  17.     /*
  18.     int a;
  19.     item carrito[4];
  20.  
  21.     int arreglo[4];
  22.  
  23.     int elementoUno = arreglo[0];
  24.  
  25.     arreglo[0] = 10;
  26.  
  27.     //30
  28.  
  29.     carrito[1].cantidad = 30;
  30.  
  31.     //carrito = 30; error de tipo arreglo vs entero
  32.  
  33.     //carrito.cantidad = 30; no le indico cual item/indice es adecuado
  34.  
  35.     //carrito[1] = 30; no le indico la variable/caracteristica que le quiero asignar
  36.  
  37.     int cant = carrito[1].cantidad;
  38.  
  39.     printf("la cantidad es %d",cant);
  40.     */
  41.  
  42.     item producto;
  43.  
  44.     item carrito[4];
  45.  
  46.     item matriz[4][9];
  47.  
  48.     matriz[0][1].cantidad = 1;
  49.  
  50.     cargarArreglo(carrito);
  51.     mostrarArreglo(carrito);
  52.     return 0;
  53. }
  54.  
  55. void mostrarArreglo(item carrito[4])
  56. {
  57.     for (int indice = 0;indice<3; indice++)
  58.     {
  59.         printf("la cantidad es %d\n",carrito[indice].cantidad);
  60.         //printf("el precio es %f",carrito[indice].precio);
  61.     }
  62. }
  63.  
  64. void cargarArreglo(item carrito[4])
  65. {
  66.     for (int indice = 0; indice<3;indice++)
  67.     {
  68.         printf("ingrese cantidad \n");
  69.         fflush(stdin);
  70.         scanf("%d",&carrito[indice].cantidad);
  71.     }
  72. }
  73.  
  74. void unaFuncion(int a)
  75. {
  76.     a = 30;
  77.     int c = 20;
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement