Home > Back-end >  voting
voting

Time:09-21

CodePudding user response:

C language foundation
Using a struct definition structure
Use printf output some information such as menu
Use getchar to get the user's choices, such as 1, 2, and so on

CodePudding user response:

The
Quote: reference 1/f, Simple, Soft reply:

My code was losing out the results
#include
Struct person
{
char name[20];
int n;
};
Int main ()
{
int i=0;
Struct person a []={{" zhang ", 0}, {" bill ", 0}, {" detective ", 0}, {" x 6 ", 0}};
Printf (" the name of the four candidates for: zhang SAN, li si, fifty and six; \n");
Printf (" please enter the number vote for the candidate (1 for threes, 2 for li si, 3 for fifty, four to six, five voting ended) \ n ");
Char tick;

for(i=0; i<10; I++)
{
Printf (" \ t first voter % d ", I + 1);
Gets (& amp; Tick); }
While (I!//if a judgment is equal to 5=5), jump out of the cycle (
{
The scanf (" % d ", & amp; I);
The switch (I)
{
Case 1: a [0]. N++; break;
Case 2: a [1]. N++; break;
Case 3: a [2]. N++; break;
Case 4: a [3]. N++; break;
}
}
for(i=0; i<4. I++)
{
Vote for printf (" % d: % d ", a [I]. Name, a [I] n);
}
return 0;
}

CodePudding user response:

Gets the function of the () function from the input buffer pointer variable reads a string stored in the characters in STR is pointing to the memory space

So the gets (& amp; Tick); This kind of writing is wrong, can use the tick=getchar ()