PDA

View Full Version : سلام...مشکل این کد چیه



ali_1369
چهارشنبه 11 دی 1387, 11:34 صبح
این برنامه اظلاعات چند دانشجو رو میگیره و تو فایل ذخیری میکنه ولی نمیدونم مشکلش چیه

#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define n 6
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 bublle1 (void);
void bublle(void);
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();bublle(),bublle1();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;
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]);
}}
//************************
void bublle(void)
{
int j;
char temp[30];
for(j=0;st[j-1];j++)
if(strcmp(st[j].name,st[j+1].name)>=0){
strcpy(temp,st[j].name);
strcpy(st[j].name,st[j+1].name);
strcpy(st[j+1].name,temp);
}
}
//********************
void bublle1 (void){
int i=0,j=0,temp=0;
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;
}}}}

//***********************
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 search(void)
{
int num2=0,i,r=0,j,k;
char name2[30],ans;
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 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){
int i,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++;}}}

sang9111
چهارشنبه 11 دی 1387, 14:29 عصر
من یه نگاه کردم اشکال نحوی خیلی زیاد داره
مثلا:
در خط 91 شماره آرایه شما دارید از j که مساوی صفر است یک رقم دیگه کم می کنید میشه -1
فکر می کنم در خط آخرم یه دونه کروشه زیاد گذاشته باشید
کامپایلر من از gotoxy پشتیبانی نمی کنه
اشکالات دیگه هم داره که باید بیشتر دقت کرد خوب نگاه کنید پی می برید