ايران ويج

نسخه‌ی کامل: مشکل این کد چیه؟
شما در حال مشاهده‌ی نسخه‌ی متنی این صفحه می‌باشید. مشاهده‌ی نسخه‌ی کامل با قالب بندی مناسب.
سلام....من یه برنامه نوشتم که مشخصات چنتا دانشچو رو میگیره و تو فایا ذحیره میکنه اما نمیدونم مشکلش چیه
کد:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const int n=10;
struct student {
char name [30] ;
int number;
float score [10];
char lesson [10][10];
int unit[10];
float avrage;
int amount;
}
st[10];
int i,j;
int menu_select(int);
void top_fail(void);
void enter(void);
void search (void);
void printall(void);
void save (void);
void load (void);
int main()
{
int choice;
for(;;) {
choice = menu_select(choice);
switch (choice){
case 1:enter();break;
case 2: printall();break;
case 3: search();break;
case 4:top_fail();break;
case 5:save();break;
case 6:load();break;
}
}
getch();
return 0;
}
//*******************
int menu_select(int choice){


printf("(1)<<enter info>>");
printf("\n(2)<<viwe all info>>");
printf("\n(3)<<serach a name or number>>");
printf("\n(4)<<top or fail students>>");
printf("\n(5)save all info");
printf("\n(6)load all data");

printf("\nplease enter your chice:(1-6)");
scanf("%d",&choice);
if (choice>=0||choice<=6)
return (choice);
if(choice>=7)
printf("yor choice is not included in option");
}


//**********************
void enter(void){

int i,j,temp=0,r=0,k,num2,javab;
char temp1[30],ans,name2[30];
for(i=0;i<n;i++)
{
printf("\nenter the name:");
gets(st[i].name);

printf("\nenter the student number:");
scanf("%d",&st[i].number);
printf("\nenter the number of lesson:");
scanf("%d",&st[i].amount);
printf("\nenter leesons name:");
for(j=0;j<st[i].amount;j++)
scanf("%s",st[i].lesson[j]);
printf("\nenter each lessons unit:");
for(j=0;j<st[i].amount;j++)
scanf("%d",&st[i].unit[j]);
printf("\nenter each lesseons score:");
for(j=0;j<st[i].amount;j++)
scanf("%d",&st[i].score[j]);}

for(i=n-1;i>0;i--){

for(j=0;j<i;j++)
if(strcmp(st[j].name,st[j+1].name)>=0){
strcpy(temp1,st[j].name);
strcpy(st[j].name,st[j+1].name);
strcpy(st[j+1].name,temp1);}}

for(i=n-1;i>0;i--){
for(j=0;j<i;j++){
if(st[j].number>st[j+1].number){
temp=st[j].number;
st[j].number=st[j+1].number;
st[j+1].number=temp;}}

printf("do you want to search in the list?(1-y/2-n)");
scanf("%d",&javab);
if(javab=='y'){
printf("what do you want to search?1-name,2-number(1or2)");
ans=getche();
switch (ans){
case '1':
printf("enter the name you are looking for:");
gets(name2);
for(i=0;i<n;i++){
if(strcmp(st[i].name,name2)==0){
gotoxy(25,2);
printf("the info about this prson:");
gotoxy(13,3);
printf("*********************");
printf("***********************");
printf("************************");
gotoxy(10,4);
printf("name number lesseon ");
printf("score avrage");
gotoxy(10,5);
printf("----- ----- ----");
printf("----- -----");
gotoxy(14,7+r);
puts(st[i].name);
gotoxy(26,7+r);
printf("%d",st[i].number);
gotoxy(40,7+r);
for(j=0;j<st[i].amount;j++){
puts(st[i].lesson[j]);
}
gotoxy(54,7+r);
for(k=0;k<st[i].amount;k++){
printf("%d",st[i].score[k]);
}
gotoxy(70,7+r);
printf("%f",st[i].avrage);
break;
case '2':
printf("enter the number:");
scanf("%d",&num2);
for(i=0;i<n;i++){
if(st[i].number==num2){
gotoxy(25,2);
printf("the info about this prson:");
gotoxy(13,3);
printf("*********************");
printf("***********************");
printf("************************");
gotoxy(10,4);
printf("name number lesseon ");
printf("score avrage");
gotoxy(10,5);
printf("----- ----- ----");
printf("----- -----");
gotoxy(14,7+r);
puts(st[i].name);
gotoxy(26,7+r);
printf("%d",st[i].number);
gotoxy(40,7+r);
for(j=0;j<st[i].amount;j++){
puts(st[i].lesson[j]);
}
gotoxy(54,7+r);
for(k=0;k<st[i].amount;k++){
printf("%d",st[i].score[k]);
}
gotoxy(70,7+r);
printf("%f",st[i].avrage);

}}

//***********************
void top_fail(void){

int i,j;
float sum,sum1;
for(i=0;i<n;i++){
sum=0;sum1=0;
for(j=0;j<st[i].amount;j++){
sum+=st[i].unit[j]*st[i].score[j];
sum1+=st[i].unit[j];}
st[i].avrage=sum/sum1;}
for(i=0;i<n;i++){
if(st[i].avrage>17){
printf("the top students are:");
puts(st[i].name);
}

if(st[i].avrage<12){
printf("the failed students are:");
puts(st[i].name);}}}
//****************************

void save(void);{
FILE *fp ;
fp=fopen("e:st","wb");
if(!fp){
printf("the file can not be opend");
getch();
return ;}
for(i=0;i<=n;i++){
if(*st[i].name)
fwrite(&st[i],sizeof(struct student),1,fp);
}
printf("info now are saved");}
//**************************
void load(void){
FILE *fp;
fp=fopen("E:st","rb");
if(!fp){
printf("can not open the foile"):
getch():
return;
}
for(i=0;i<=n;i+++){
fread(&st[i],sizeof(struct student),1,fp);
if(feof(fp))
{
printf("info loaded");
return ;
}}}
//**************************
void printall(void)
{


register i;
int r=0,k,j,n;
gotoxy(25,2);
printf("all info:");
gotoxy(13,3);
printf("*********************");
printf("***********************");
printf("************************");
gotoxy(10,4);
printf("name number lesseon ");
printf("score avrage");
gotoxy(10,5);
printf("----- ----- ----");
printf("----- -----");
for(i=0;i<n;++i){
gotoxy(14,7+r);
puts(st[i].name);
gotoxy(26,7+r);
printf("%d",st[i].number);
gotoxy(40,7+r);
for(j=0;j<st[i].amount;j++){
puts(st[i].lesson[j]);
}
gotoxy(54,7+r);
for(k=0;k<st[i].amount;k++){
printf("%d",st[i].score[k]);
}
gotoxy(70,7+r);
printf("%f",st[i].avrage);
r++;}}
}
دلیل ویرایش :استفاده از تگ کد برای خوانایی کد