Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hi, im trying to add each array address into a variable, but it won't work.
- // Mayor's Race.cpp : Defines the entry point for the console application.
- //
- /* James Inglis
- * Introduction to Prgramming
- * Mr.Hunter
- * 11/24/12
- * Project 10 Chapter 7
- */
- #include "stdafx.h"
- #include <stdio.h>
- #define SIZE 5 /* the size of the array */
- #define PERCENT .50 /* the 50% use to calucate the winner */
- void instruction(void);/* Displaying the users instructions */
- int add_total(const int a[], const int b[], const int c[], const int d[]);
- int
- main(void)
- {
- 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];
- instruction();
- printf("Precincts\n 1\n 2\n 3\n 4\n 5\n");
- printf("\nPlease enter the votes for candidate A > ");
- for ( i = 0; i < SIZE; ++i)
- {
- scanf_s("%d", &can_a[i]);
- }
- for ( i = 0; i < SIZE; ++i)
- {
- printf("Your votes are %d\n", can_a[i]);
- }
- printf("\nPlease enter the votes for candidate B > ");
- for ( i = 0; i < SIZE; ++i)
- {
- scanf_s("%d", &can_b[i]);
- }
- for ( i = 0; i <SIZE; ++i)
- {
- printf("Candidate B %d\n", can_b[i]);
- }
- printf("\nPlease enter the Candidate C votes > ");
- for ( i = 0; i < SIZE; ++i)
- {
- scanf_s("%d", &can_c[i]);
- }
- for ( i = 0; i < SIZE; ++i)
- {
- printf("Candidates C %d\n", can_c[i]);
- }
- printf("\n Please enter the Candidate D votes > ");
- for ( i = 0; i < SIZE; ++i)
- {
- scanf_s("%d", &can_d[i]);
- }
- for ( i = 0; i < SIZE; ++i)
- {
- printf("Candidates D %d\n", can_d[i]);
- }
- get_total = add_total(a, b, c, d);
- return 0;
- }
- void
- instruction(void)
- {
- printf("This Program lists candidates A- D. This Program computes the total votes for each candidate.\n");
- printf("\nThen, declars a winner if the one of the candidates have more than 50% of the total votes\n");
- printf("\nYou may Press <ENTER> or <RETURN> when ready\n");
- }
- int
- add_total(const int a[], const int b[], const int c[], const int d[])
- {
- 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;
- for ( v= 0; v < SIZE; ++v)
- {
- total_a[v] = *can_a[0] + *can_a[1] + *can_a[2] + *can_a[3] + *can_a[4];
- }
- printf("Your total for candidate A is %d", total_a[v]);
- for ( v = 0; v < SIZE; ++v)
- {
- total_b[v] = *can_b[0] + *can_b[1] + *can_b[2] + *can_b[3] + *can_b[4];
- }
- printf("Your total for candidate B is %d", total_b[v]);
- for ( v = 0; v < SIZE; ++v)
- {
- total_c[v] = *can_c[0] + *can_c[1] + *can_c[2] + *can_c[3] + *can_c[4];
- }
- printf("Your total for candidate C is %d", total_c[v]);
- for ( v = 0; v < SIZE; ++v)
- {
- total_d[v] = *can_d[0] + *can_d[1] + *can_d[2] + *can_d[3] + *can_d[4];
- }
- printf("Your total for candidate D is %d", total_d[v]);
- return (get_total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement