PDA

View Full Version : رفع کردن error



ali_1369
چهارشنبه 11 دی 1387, 19:33 عصر
سلام ....من میحوام یه برنامه بنویسم که اسم وشماره دانشجویی . نمره.تعداد دروس.نمره هر درس.و واحد ها رو بگیره بعد اطلاعات رو یه صورت صعودی چاپ کنه...دانشجوهای ممتاز و مشروط رو تعیین کنه قابلست search بر اساس فیلدهای اسم و شماره داشته باشه........خودم یه چیزیایی نوشتم ولی چنتا تا خطا داره نمیتونم تصحیح کنم ممنون میشم کمک کنید


#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++;}}}

ميثم طاهري
جمعه 13 دی 1387, 18:31 عصر
#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++;}}}

ali_1369
شنبه 14 دی 1387, 19:31 عصر
سلام...............کسی نمیتونه کمک کنه؟

Saeed_m_Farid
شنبه 14 دی 1387, 19:56 عصر
سلام...............کسی نمیتونه کمک کنه؟
دوست عزيز با اين كد نامرتبي كه ليست كردين نه نميشه؛ محبت كنين مرتبش كنيد و بذاريدشون تو تگ كد تا قابل فهم بشه.

ali_1369
یک شنبه 15 دی 1387, 12:04 عصر
دوست عزيز با اين كد نامرتبي كه ليست كردين نه نميشه؛ محبت كنين مرتبش كنيد و بذاريدشون تو تگ كد تا قابل فهم بشه.




#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++;}}
}

ali_1369
یک شنبه 15 دی 1387, 12:15 عصر
دوست عزيز با اين كد نامرتبي كه ليست كردين نه نميشه؛ محبت كنين مرتبش كنيد و بذاريدشون تو تگ كد تا قابل فهم بشه.


سلام....اگه نگاه کنید جناب طاهری زحمت این کارو کشیدن.......نقل قول دوم.