Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
Megha J VParticipant
Could u plz help me in code of voting machine whr the code has to be done with some modifications.
the control according to the code is taking many votes at a time but in voting the control shud go back to the entry state where it takes only one input
Code is :
#include<stdint.h>#include<stdio.h>#include "scankey.h"#include "NUC1xx.h"#include "DriverDrvSYS.h"#include "NUC1xx-LB_002LCD_Driver.h"int32_t main (void){int8_t arr[4];int8_t vote_amt[3],j;int8_t vote1,vote2,vote3,vote4;int8_t i;char T[1]=":";int8_t carry;int8_t max=0;char p1[50]=":";char p2[50]="::";int8_t candidate;int8_t number8;char t1[50]="a";char t2[50]=": ";char TEXT0[50]="Press 8 to vote ";char TEXT1[50]="WELCOME! VOTE P1 P2 P3 P4";vote1 = vote2 = vote3 = vote4 = 0;UNLOCKREG();DrvSYS_Open(48000000); // set MCU to run at 48MHzLOCKREG();Initial_panel();clr_all_panel();OpenKeyPad(); // initialize 3×3 keypadprint_lcd(0,TEXT0); // print titlewhile(1){number8=Scankey();//number9=Scankey();while(number8 =={Initial_panel();clr_all_panel();print_lcd(0,TEXT1);DrvSYS_Delay(5000000);Initial_panel();clr_all_panel();while(1){candidate=Scankey();sprintf(t2,"%d",candidate);print_lcd(2,t2);DrvSYS_Delay(5000000);//functionwhile(candidate==1){Initial_panel();clr_all_panel();sprintf(p1,"%d",candidate);print_lcd(2,p1);DrvSYS_Delay(5000000);while(candidate==1){Initial_panel();clr_all_panel();print_lcd(0,"Candidate1");vote1 = vote1 + 1;sprintf(p2,"%d",vote1);print_lcd(2,p2);DrvSYS_Delay(5000000);break;}break;}while(candidate==2){Initial_panel();clr_all_panel();sprintf(p1,"%d",candidate);print_lcd(2,p1);DrvSYS_Delay(5000000);while(candidate==2){Initial_panel();clr_all_panel();print_lcd(0,"Candidate2");vote2 = vote2 + 1;sprintf(p2,"%d",vote2);print_lcd(2,p2);DrvSYS_Delay(5000000);break;}break;}while(candidate=){Initial_panel();clr_all_panel();sprintf(p1,"%d",candidate);print_lcd(2,p1);DrvSYS_Delay(5000000);while(candidate=){Initial_panel();clr_all_panel();print_lcd(0,"Candidate3");vote3 = vote3 + 1;sprintf(p2,"%d",vote3);print_lcd(2,p2);DrvSYS_Delay(5000000);break;}break;}while(candidate==4){Initial_panel();clr_all_panel();sprintf(p1,"%d",candidate);print_lcd(2,p1);DrvSYS_Delay(5000000);while(candidate==4){Initial_panel();clr_all_panel();print_lcd(0,"Candidate4");vote4 = vote4 + 1;sprintf(p2,"%d",vote4);print_lcd(2,p2);DrvSYS_Delay(5000000);break;}break;}if(candidate==9)break;}while(candidate==9){while(1){Initial_panel();clr_all_panel();print_lcd(0,"RESULTS ARE OUT");print_lcd(1,"P1 P2 P3 P4");sprintf(T,"%d %d %d %d",vote1,vote2,vote3,vote4);print_lcd(2,T);DrvSYS_Delay(90000000);//delay(300); arr[0] = vote1;arr[1] = vote2;arr[2] = vote3;arr[3] = vote4;for( i=0; i<4; i++){if(arr>=max)max = arr;}while(1){if ( (vote1 == max) && ( vote2 != max) && (vote3 != max)&& (vote4 != max) ){carry = 1;Initial_panel();clr_all_panel();print_lcd(2,"P1 WON!");DrvSYS_Delay(300000000);}if ( (vote1 != max) && ( vote2 == max) && (vote3 != max)&& (vote4 != max) ){carry = 1;Initial_panel();clr_all_panel();print_lcd(2,"P2 WON!");DrvSYS_Delay(300000000);}if ( (vote1 != max) && ( vote2 != max) && (vote3 == max)&& (vote4 != max) ){carry = 1;Initial_panel();clr_all_panel();print_lcd(2,"P3 WON!");DrvSYS_Delay(300000000);}if ( (vote1 != max) && ( vote2 != max) && (vote3 != max)&& (vote4 == max) ){carry = 1;Initial_panel();clr_all_panel();print_lcd(2,"P4 WON!");DrvSYS_Delay(300000000);}}}}}}} -
AuthorPosts
Viewing 1 post (of 1 total)