Advertisement
jinglis

Mayor's Race

Nov 26th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. Hi, im trying to add each array address into a variable, but it won't work.
  2.  
  3. // Mayor's Race.cpp : Defines the entry point for the console application.
  4. //
  5. /* James Inglis
  6.  * Introduction to Prgramming
  7.  * Mr.Hunter
  8.  * 11/24/12
  9.  * Project 10 Chapter 7
  10.  */
  11.  
  12.  
  13. #include "stdafx.h"
  14. #include <stdio.h>
  15. #define SIZE 5       /* the size of the array */
  16. #define PERCENT .50  /* the 50% use to calucate the winner */
  17. void instruction(void);/* Displaying the users instructions */
  18. int add_total(const int a[], const int b[], const int c[], const int d[]);
  19.  
  20.  
  21. int
  22. main(void)
  23. {
  24.     int can_a[SIZE], can_b[SIZE], can_c[SIZE], can_d[SIZE], i, total_a[SIZE], total_b[SIZE], total_c[SIZE], total_d[SIZE], get_total, a[SIZE], b[SIZE], c[SIZE], d[SIZE];
  25.  
  26.     instruction();
  27.  
  28.     printf("Precincts\n 1\n 2\n 3\n 4\n 5\n");
  29.     printf("\nPlease enter the votes for candidate A > ");
  30.  
  31.     for ( i = 0; i < SIZE; ++i)
  32.     {
  33.         scanf_s("%d", &can_a[i]);
  34.     }
  35.    
  36.    
  37.     for ( i = 0; i < SIZE; ++i)
  38.     {
  39.  
  40.         printf("Your votes are %d\n", can_a[i]);
  41.     }
  42.  
  43.     printf("\nPlease enter the votes for candidate B > ");
  44.  
  45.     for ( i = 0; i < SIZE; ++i)
  46.     {
  47.         scanf_s("%d", &can_b[i]);
  48.     }
  49.  
  50.     for ( i = 0; i <SIZE; ++i)
  51.     {
  52.         printf("Candidate B %d\n", can_b[i]);
  53.     }
  54.  
  55.     printf("\nPlease enter the Candidate C votes > ");
  56.  
  57.     for ( i = 0; i < SIZE; ++i)
  58.     {
  59.         scanf_s("%d", &can_c[i]);
  60.     }
  61.  
  62.     for ( i = 0; i < SIZE; ++i)
  63.     {
  64.         printf("Candidates C %d\n", can_c[i]);
  65.     }
  66.  
  67.     printf("\n Please enter the Candidate D votes > ");
  68.  
  69.     for ( i = 0; i < SIZE; ++i)
  70.     {
  71.         scanf_s("%d", &can_d[i]);
  72.     }
  73.  
  74.     for ( i = 0; i < SIZE; ++i)
  75.     {
  76.         printf("Candidates D %d\n", can_d[i]);
  77.     }
  78.  
  79.     get_total = add_total(a, b, c, d);
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.     return 0;
  87. }
  88.  
  89. void
  90. instruction(void)
  91. {
  92.     printf("This Program lists candidates A- D. This Program computes the total votes for each candidate.\n");
  93.     printf("\nThen, declars a winner if the one of the candidates have more than 50% of the total votes\n");
  94.     printf("\nYou may Press <ENTER> or <RETURN> when ready\n");
  95. }
  96.  
  97. int
  98. add_total(const int a[], const int b[], const int c[], const int d[])
  99. {
  100.     int total_a[SIZE], total_b[SIZE], total_c[SIZE], total_d[SIZE], v, get_total, *can_a[SIZE], *can_b[SIZE], *can_c[SIZE], *can_d[SIZE], i;
  101.  
  102.     for ( v= 0; v < SIZE; ++v)
  103.     {
  104.         total_a[v] = *can_a[0] + *can_a[1] + *can_a[2] + *can_a[3] + *can_a[4];
  105.     }
  106.     printf("Your total for candidate A  is %d", total_a[v]);
  107.  
  108.     for ( v = 0; v < SIZE; ++v)
  109.     {
  110.         total_b[v] = *can_b[0] + *can_b[1] + *can_b[2] + *can_b[3] + *can_b[4];
  111.     }
  112.  
  113.     printf("Your total for candidate B is %d", total_b[v]);
  114.  
  115.     for ( v = 0; v < SIZE; ++v)
  116.     {
  117.         total_c[v] = *can_c[0] + *can_c[1] + *can_c[2] + *can_c[3] + *can_c[4];
  118.     }
  119.  
  120.     printf("Your total for candidate C is %d", total_c[v]);
  121.  
  122.     for ( v = 0; v < SIZE; ++v)
  123.     {
  124.         total_d[v] = *can_d[0] + *can_d[1] + *can_d[2] + *can_d[3] + *can_d[4];
  125.     }
  126.  
  127.     printf("Your total for candidate D is %d", total_d[v]);
  128.  
  129.     return (get_total);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement