Thread: how can i make the data that i input in a function appear in another one?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'm still not sure, because I only see a function that inputs data and no function that outputs any of the inputted data.
    But what I can say is this: you do realize that you're using local variables, right? They will disappear when the function exits and can't be accessed from any other function.
    You also seem to have declared a struct, but you're not filling its member variables, but instead, you're filling extra copies local variables.

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    66
    I think you want a loop.

    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
    void ingresar();
    void revisar();
    main()
    {
     int op;
     int cap[CAP];
     int miliseg[SEG];
     float cost[COST];
     float prec[PREC];
     char codven[COD];
     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();
    	  break;
              }
      case 2:{
    	  revisar();
    	  break;
              }
      default:{
    	   printf("\n\nOpcion incorrecta.");
    	   break;
    	   }
      }
      }
     return 0;
    }
    
    
    void ingresar()
    {
     struct Discos
     {
      int op;
      int cap[CAP];
      int miliseg[SEG];
      float cost[COST];
      float prec[PREC];
      char codven[COD];
     } discos;
    
     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", &cap[1]);
     printf("\nTiempo de acceso en milisegundos: ");
     scanf("%d", &miliseg[1]);
     printf("\nCodigo del vendedor (A, B, C, D): ");
     scanf("%s", &codven[1]);
     printf("\nCosto de fabrica: ");
     scanf("%f", &cost[1]);
     printf("\nPrecio de venta al publico: ");
     scanf("%f", &prec[1]);
     return;
    }
    
    void revisar()
    {
     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 ;
    }
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM