最简单投票网站代码c(html投票代码)
admin 发布:2022-12-19 06:23 165
今天给各位分享最简单投票网站代码c的知识,其中也会对html投票代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、C语言投票程序
- 2、C语言选民投票管理系统代码
- 3、求助。C语言做的一个投票系统
- 4、求做C语言的投票系统
- 5、c语言 投票程序
C语言投票程序
提示输入,可以直接输入下标,0~2。
这样就不需要判断了。还能避免输入错误。
提示输入的文字建议用循环动态生成。这样方便后期扩展,比如变成5个人。
提示输入的文字大致可以这样写:
把数组大小定义成常量,方便修改,比如#define SIZE 3
printf("请输入对应数字,为下列人物投票:");
for(i=0;iSIZE;i++)
printf("%d:%s ",i,arr[i].name);
这样后面输入只要输入结构数组下标,就可以直接++,无需判断。
C语言选民投票管理系统代码
#includestdio.h
#includestring.h
#includestdlib.h
struct person
{
char name[10];
int num;
int age;
} leader
void main()
{
void start();
void admin();
void customer();
char a;
scanf("c",a);
if(a==#) admin();
if(a==*) customer();
}
void start()
{
printf("******************");
printf("*欢迎进入投票系统*");
printf("*********************");
printf("#管理穿口");
printf("*选民进口");
}
void admin()
{
int a ;
void admin1();
printf("**********");
printf("*管理员才可以进入");
printf("*请输入密码:");
printf("password: *");
printf("********");
scanf("d",a);
clrscr();
for(i=1;i3;i++)
{if (a==123456)br {printf("**********");br printf("登陆成功");br printf("**********");br admin1();br clrscr();br break;}
else
{printf("***********");br printf("*密码错误,请重新输入,您共有三次机会")br }
}
void admin1()
{
int b;
printf("**********");
printf("*1.查询候选人信息*");
printf("*2.查询候选人票数*");
printf("*3.录入候选人信息*");
printf("*请输入: *");
printf("*************");
scanf("d",b);
if (b==1) admin11();
if (b==2) admin12();
if (b==3) admin13();
}
void admin13()
{
int i;
printf("请输入候选人信息:")
for(i=0;i3;i++)
scanf("% s% d% %d s",leader[i].name,leader[i].num,leader[i].age,leader[i],addr);
save();
}
void save ()
{
file *fp;
int i;
if(fp=fopen("leader_dat","wb"==NULL))
{
printf("cannot open file\n");
return;
}
for(i=0;i3;i++)
if(fwrite(leader[i],sizeof(struct leader_type,1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void admin12()
{
int i;
file*fp;
if((sp=fopen("leader_dat""rb"))=NUll
{
printf("cannot open file\n");
return;
}
for(i=0;i3;i++)
{
fread (leader[i],sizeof(struct leader_type),1,fp);
printf("%-10s %4d % 4d %-15s\n",leader[i].name,leader[i].num,leader[i].age,leader[i].addr)
}
fclose(fp);
}
customer()
{
int c;
printf("*************");
printf("*1.查询候选人信息*");
printf("*2.进入投票系统*");
printf("请输入: ");
scanf("%d,c");
if(c==1) admin12();
if(c==2) vote();
}
void vote()
{
int i,j;
admin12();
for(i=1;i=10;i++)
{
scanf("%s",leader_name);
if(strcmp(leader_name,leader[j],name==0)) leader[j].count++;
}
}
求助。C语言做的一个投票系统
#define PRT(j,k) printf("j的票数为%d",k);
这里你如果想要J显示你想要的内容的话直接 把j放在双引号的外面就可以了,
#define PRT(j,k) printf(j“的票数为%d",k);
但是这里注意的是你传入的j的值就一定要是字符串形式的,就比如 调用PRT(”jack“,10)
那么显示出来就会是 jack的票数为10
调试了一下发现要把hxr定义为hxr[2]才行
想了下也就是hxr要把\0也接收到才行
首先你定义hxr为char型,一个char型,你需要使用 %c 去接受,改成scanf("%c",hxr);
还有 scanf以后注意谨慎使用,用多了以后你会发现 scanf会很容出问题。
求做C语言的投票系统
#include stdio.h
#include stdlib.h
typedef struct node
{ // 候选人结构
char name[8];
int num;
int score;
int tax;
}Node;
void shellSort( Node **, int );
int main(void)
{
int n = 0;
Node * pArray[9]={};//指针数组,长度9
int count = 0;
//int status = 1;
int vote = -1;
printf("Input the number of the candidates(1-9):\n");
scanf("%d", n);
while(getchar()!='\n')
{
;
}
while (n9 || n1)
{
if (n9)
{
printf("No, there cannot be so many candidates. Retry.\n");
}
else
{
printf("No candidates? It cannot be! Retry!\n");
}
scanf("%d", n);
while(getchar()!='\n')
{
;
}
}
for (count=0; countn; count++)
{
pArray[count] = (Node *)malloc(sizeof(Node));
pArray[count]-num = count+1;
pArray[count]-tax = 0;
pArray[count]-score = 0;
printf("Input No.%d candidate's name:\n", count+1);
gets(pArray[count]-name);
}
while (vote)
{
printf("Now, let us vote:\n*************\n");
for (count=0; countn; count++)
{
printf("%d. %s\n", count+1, pArray[count]-name);
}
printf("0.quit\n*************\n");
scanf("%d", vote);
while(getchar()!='\n')
{
;
}
while (vote0 || voten)
{
printf("No joke, thank you. Revote.\n");
scanf("%d", vote);
while(getchar()!='\n')
{
;
}
}
if (vote0vote=n)
{
pArray[vote-1]-score++;
}
}
printf("Finish voting. Let's find the winner......\n\n");
shellSort( pArray, n );
for (count=0; countn; count++)
{
pArray[count]-tax=count+1;
printf("%d. %s %d votes.\n", count+1, pArray[count]-name, pArray[count]-score);
}
for(count=0; countn; count++)
{
free(pArray[count]);
pArray[count] = NULL;
}
return 0;
}
void shellSort( Node *p[], int len )
{
const int Length = len;
int i = 0;
int j = 0;
int gap = 0;
Node *temp = NULL;
gap = Length/2;
while (gap0)
{
for (i=gap; iLength; i++)
{
j = i - gap;
temp = *(p+i);
while ( (j=0) (p[j]-score temp-score) )
{
*(p+j+gap) = *(p+j);
j = j - gap;
}
*(p+j+gap) = temp;
}
gap /= 2;
}
}
运行与输入方式:
1.程序提示,输入候选人人数, 输入数字(1-9),大于9或小于1或者输入不合法字符会提示错误。
2.程序提示依次输入候选人名字,不能超过7个字符(少了点,你题目给的,数组拉长点会更安全些)
3.按照程序提示的数字开始投票,或者退出。
4.投票过程结束后,程序调用shellSort(希尔排序)函数对所有参选人按照得票数目进行降序排序,并将排序结果输出。
c语言 投票程序
给你写一个:
#includestdio.h
#define M 100 //投票人数上限
#define N 3 //候选人数
struct
{
char code; //代号
int score; //得分
} candidates[N], st; //候选人结构体数组
int main()
{
char candidate[M][N]; //投票
int n, c=0; //n: 实际投票人数,c: 有效选票
int i,j,k,t;
char tmp[N+1]; //存放投票的中间变量
int s[N]={5,3,2};
for(i=0; iN; ++i)
{
printf("输入第 %d 个候选人的代号:", i+1);
scanf("%c", candidates[i].code);
fflush(stdin); //清除回车符
candidates[i].score=0;
}
printf("输入投票人数:");
scanf("%d",n);
for(i=0; in; ++i) //输入选票
{
printf("输入第 %d 张选票:", i+1);
scanf("%s",tmp);
candidate[i][0]=tmp[0];
candidate[i][1]=tmp[1];
candidate[i][2]=tmp[2];
if(tmp[0]==tmp[1] || tmp[1]==tmp[2] || tmp[0]==tmp[2])
printf("该票无效:%s\n", tmp);
else
{
//tmp[0]号候选人加5分;
//tmp[1]号候选人加3分;
//tmp[2]号候选人加2分;
c++;
for(j=0; jN; ++j)
for(k=0; kN; ++k)
if(candidates[k].code==tmp[j])
candidates[k].score+=s[j];
}
}
//得分排序
for(i=0; iN-1; ++i)
{
k=i;
for(j=i+1; jN; ++j)
if(candidates[j].scorecandidates[k].score)
k=j;
st=candidates[i];
candidates[i]=candidates[k];
candidates[k]=st;
}
if(candidates[0].score==candidates[1].score)
printf("前两名得分是否相同,都是 %d 分,重新投票。", candidates[0].score);
else
{
printf("候选人\t得分\n");
for(i=0; iN; ++i)
printf("%c\t%d\n", candidates[i].code, candidates[i].score);
printf("祝贺 %c 当选冠军!\n", candidates[0].code);
}
return 0;
}
关于最简单投票网站代码c和html投票代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:asp广告代码(ASP程序代码)
- 下一篇:网络办公系统源代码(办公软件代码编程)
相关推荐
- 05-19国内好的seo网站,好的seo平台
- 05-19做网站公司,做网站公司电话
- 05-19如何推广网站,如何推广网站让客户下单
- 05-19如何做网站,如何做网站网页
- 05-19广东网站seo,广东网站制作
- 05-19网站如何优化一个关键词,怎么优化一个网站关键词
- 05-19seo网站,seo网站是什么意思
- 05-19免费seo网站自动推广,国内免费舆情网站有哪些软件
- 05-19怎么做网站,怎么做网站教程视频
- 05-19推广平台网站,推广平台网站犯法吗
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接