🔒 Closed C Program paano po gawin to. Pa tulong po

Status
Not open for further replies.

XsanX

𝑩𝑶𝑹𝑵 𝑻𝑶 𝑩𝑬 𝑵𝑶𝑻𝑯𝑰𝑵𝑮

Mini Voting C program

Hindi ko po talaga alam ano dapat gawin nito, Yung gusto ko po sana yung pag ka tapos mo mag cast sa 1st candidates (Mayor) dapat susunod na sa (Vice mayor ) mag vovote kaya lang hindi ko po makuha anong timpla gagawin

C:
#include<stdio.h>

#define CANDIDATE_COUNT

#define CANDIDATE1 "David Hull"
#define CANDIDATE2 "Kristin Canella"
#define CANDIDATE3 "Jim Brar"
#define CANDIDATE4 "Donald Truimph"

int votesCount1=0, votesCount2=0, votesCount3=0, votesCount4=0, spoiledtvotes=0;

void castVote(){
int choice; 
printf("\n\n ### Please choose your Candidate ####\n\n");
printf("\n 1. %s", CANDIDATE1);
printf("\n 2. %s", CANDIDATE2);
printf("\n 3. %s", CANDIDATE3);
printf("\n 4. %s", CANDIDATE4);
printf("\n 5. %s", "None of These");

printf("\n\n Input your choice (1 - 4) : ");
scanf("%d",&choice);

switch(choice){
    case 1: votesCount1++; break;
    case 2: votesCount2++; break;
    case 3: votesCount3++; break;
    case 4: votesCount4++; break;
    case 5: spoiledtvotes++; break;
    default: printf("\n Error: Wrong Choice !! Please retry");
             /*hold the screen*/
             getchar();
}
printf("\n thanks for vote !!");
}

void votesCount(){
printf("\n\n ##### Voting Statics ####");
printf("\n %s - %d ", CANDIDATE1, votesCount1);
printf("\n %s - %d ", CANDIDATE1, votesCount2);
printf("\n %s - %d ", CANDIDATE1, votesCount3);
printf("\n %s - %d ", CANDIDATE1, votesCount4);
printf("\n %s - %d ", "Spoiled Votes", spoiledtvotes);
}

void getLeadingCandidate(){
    printf("\n\n  #### Leading Candiate ####\n\n");
    if(votesCount1>votesCount2 && votesCount1>votesCount3 && votesCount1 >votesCount4)
    printf("[%s]",CANDIDATE1);
    else if (votesCount2>votesCount3 && votesCount2>votesCount4 && votesCount2 >votesCount1)
    printf("[%s]",CANDIDATE2);
    else if(votesCount3>votesCount4 && votesCount3>votesCount2 && votesCount3 >votesCount1)
    printf("[%s]",CANDIDATE3);
    else if(votesCount4>votesCount1 && votesCount4>votesCount2 && votesCount4 >votesCount3)
    printf("[%s]",CANDIDATE4);
    else
    printf("----- Warning !!! No-win situation----"); 
  
  
  
}

int main()
{
int i;
int choice;

do{
printf("\n\n ###### Welcome to Election/Voting 2019 #####");
printf("\n\n 1. Cast the Vote");
printf("\n 2. Find Vote Count");
printf("\n 3. Find leading Candidate");
printf("\n 0. Exit");

printf("\n\n Please enter your choice : ");
scanf("%d", &choice);

switch(choice)
{
case 1: castVote();break;
case 2: votesCount();break;
case 3: getLeadingCandidate();break;
default: printf("\n Error: Invalid Choice");
}
}while(choice!=0);

/*hold the screen*/
getchar();

return 0;
}
 
Just a suggestion.
1. Create a list of positions and respective candidates
2. Cast vote for the first position if castVote() is selected
3. Check if has next position, castVote() else end return to main menu

I think C has a "goto" function.
 
Just a suggestion.
1. Create a list of positions and respective candidates
2. Cast vote for the first position if castVote() is selected
3. Check if has next position, castVote() else end return to main menu

I think C has a "goto" function.
Yes ganyan nga yung process lods, nahihirapan kase ako pano e code

Up, nahihirapan ako sa kalisod hahahahah
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 502
    Views
  • 2
    Participants
Last reply from:
XsanX

Online now

Members online
563
Guests online
1,206
Total visitors
1,769

Forum statistics

Threads
2,277,846
Posts
28,979,231
Members
1,229,107
Latest member
worldteens2021
Back
Top