Advertisement
Mastercpp

Elecciones

Nov 2nd, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. void votos(){
  5.         char nombre[40],cedula[40];
  6.     int vmaria=0,vjuan=0,vpedro=0,vnulo=0;
  7.     FILE * datos = fopen("datos_elecciones.txt","a");
  8.         char opcion[1];
  9.  
  10.  
  11.     printf("ingrese nombre: ");
  12.     gets(nombre);
  13.  
  14.     printf("ingrese cedula: ");
  15.     gets(cedula);
  16.  
  17.     printf("\t\t\tPor quien quieres votar \n\t\t\t\1 1-Maria \n\t\t\t\1 2-juan \n\t\t\t\1 3-pedro\n");
  18.     gets(opcion);
  19.  
  20.         fputs(opcion,datos);
  21.     fclose(datos);
  22.  
  23.  
  24.     FILE * resultado = fopen("datos_elecciones.txt","r");
  25.     char c;
  26.  
  27.     if(resultado == NULL){
  28.             printf("Error en la lectura del fichero ");
  29.     }else{
  30.             while(!feof(resultado)){
  31.                 c = fgetc(resultado);
  32.  
  33.                 if(c == '1') vmaria++;
  34.                 if(c == '2') vjuan++;
  35.                 if(c == '3') vpedro++;
  36.             }
  37.     }
  38.  
  39.  
  40.     fclose(resultado);
  41.     printf("Resultado de maria %d\n",vmaria);
  42.     printf("Resultado de juan %d\n",vjuan);
  43.     printf("Resultado de pedro %d\n",vpedro);
  44. }
  45.  
  46. int main(){
  47.  
  48.     votos();
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement