PDA

View Full Version : مشکل این برنامه چیه؟



pc_math
چهارشنبه 17 بهمن 1386, 10:17 صبح
این برنامه وقتی اجرا میشه درست عمل نمی کنه:ناراحت: وقتی کامپایل می کنه ایرادی نمی گیره

#include <iostream.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define TRUE 1
void input();
int menu_select();
void maketree(struct tree *);
void find(struct tree *);
void inorder(struct tree *s);
struct tree{
struct tree *left;
char word[20];
char mean[20];
struct tree *right;
};
struct tree *start, *node;
char pword[20];
int main(){
start = NULL;
while(TRUE){
switch(menu_select()){
case 1:
input();
break;
case 2:
gotoxy(20,14);
cout<<"Enter word for search:";
cin.get(pword, 20);
find(start);
getch();
break;
case 3:
clrscr();
cout<<"\n travers tree in inorder\n";
gotoxy(6,4);
cout<<" word mean";
gotoxy(6,5);
cout<<"----------- ----------";
inorder(start);
cout<<"\n press a key to continue ....";
getch();
break;
case 4:
exit(0);
}//end of switch
}// end of while
}// end of main
//*************
void input(){
int i;
char wstr[10];
clrscr();
gotoxy(4, 3);
cout<<" word mean \n";
gotoxy(4, 4);cout<<"----------- ----------";
i = 5;
while(TRUE){
node = (struct tree *) malloc(sizeof(struct tree));
node -> left = NULL;
node -> right = NULL;
gotoxy(4, i);
cin.get(node -> word,20);
if(!node -> word[0]){
gotoxy(5, i + 2);
cout<<"\n press a key to continue ....";
getch();
break;
}
gotoxy(23, i);
cin.get(wstr, 10);
node -> mean = wstr;
if(start == NULL)
start = node;
else
maketree(start);
i++;
}// end of while
}
//************
int menu_select(){
int choice;
char s[5];
clrscr();
gotoxy(20,4);
cout<<" 1- enter word in tree.";
gotoxy(20,6);
cout<<"2- search for word in tree.";
gotoxy(20,8);
cout<<"3- print information on screen. ";
gotoxy(20,10);
cout<<"4-quit from program.";
do{
gotoxy(20,12);
cout<<"Enter your select(1-4):";
cin.get(s, 5);
choice = atoi(s);
} while(choice < 0 || choice > 4);
return choice;
}
//*****************
void maketree(struct tree *top){
struct tree *help;
help = top;
while(help != NULL){
if(node -> mean>help->mean){
if(help-> right != NULL)
help = help -> right;
else{
help -> right = node;
break;
}//end of else
}//end of if
else{
if(help-> left != NULL)
help = help -> left;
else{
help -> left = node;
break;
}//end of else
}//end of else
}//end of while
}
//******************
void find (struct tree *s){
if(s == NULL)
return;
find(s -> left);
if(strcmp(s -> word, pword) == 0){
cout<<"\n "<<pword<<" has maen:";
cout<<s -> mean;
return ;
}
find(s -> right);
}
//**********************
void inorder (struct tree *s){
if( s == NULL)
return;
inorder(s -> left);
cout<<"\n"<<s -> word;
cout<<"\t\t\t"<<s -> mean;
inorder(s -> right);
}

raravaice
چهارشنبه 17 بهمن 1386, 10:31 صبح
با چی داری کامپایلش میکنی و چه ایرادی میگیره؟

kasra515
چهارشنبه 17 بهمن 1386, 15:56 عصر
ما دو نوع ایراد تو برنامه ممکنه داشته باشیم :
1 - ایراد منطقی
2 - ایراد گرامری
اگه شما می گید که برنامه اجرا می شه ولی درست جواب نمی ده به احتمال خیلی زیاد همون مشکل منطقیه ! رفع کردن مشکل منطقی دیگران معمولا سخته ! شما هم که اصلا هیچ توضیحی ندادید ! اصلا کار این برنامه چیه ! ؟

Nima_NF
چهارشنبه 17 بهمن 1386, 16:55 عصر
این گونه تاپیک ها باید باید پاک شوند ، عنوان نا مناسب و بدون هیچ توضیحی در مورد برنامه. دقت کنید
در هر حال سریعا دو مورد فوق را رفع کنید تا تاپیک پاک نشود.




ما دو نوع ایراد تو برنامه ممکنه داشته باشیم :
1 - ایراد منطقی
2 - ایراد گرامری
ضمنا جناب kasra515 ما 4 نوع خطا داریم : منطقی ، معنایی ، نحوی ، لغوی

pc_math
چهارشنبه 17 بهمن 1386, 23:57 عصر
سلام. برنامه قراره تقریبا بشه یک دیکشنری(لغات و معانی رو به وسیله درخت حفظ کنه).
مشکلش اینه که وقتی برنامه رو اجرا می کنم منو رو نشون میده و پیغام enter a key to continue رو چاپ میکنه اگر یک دکمه بزنم پشت سر هم و بی وقفه منو رو نشون میده کاریش نمی تونم بکنم.