یک برنامه دفتر تلفن با منو میخوام که از تابع درونش استفاده شده باشه
مثلا case 'a':add'(tell
یکی کمک کنه لطفا:41::41:
با c نوشته شده باشه
++c رو پیدا کردم ولی برای c چیزی نیست
Printable View
یک برنامه دفتر تلفن با منو میخوام که از تابع درونش استفاده شده باشه
مثلا case 'a':add'(tell
یکی کمک کنه لطفا:41::41:
با c نوشته شده باشه
++c رو پیدا کردم ولی برای c چیزی نیست
[QUOTE=atabie;6845751
++c رو پیدا کردم ولی برای c چیزی نیست[/QUOTE]
فرق نداره زیاد که. کد و بذار راهنماییت میکنم کجاشو عوض کنی.
اینم چیزی که پیدا کردم ولی برای ++c هست:نقل قول:
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
int x=1;
struct tell{
char name[20];
char family[20];
int phone;
} list[100];
void add()
{if (x>=100)
cout<<"sory. the fhone book is complete"<<endl;
else
cout<<"input first name :";
cin>>list[x].name;
cout<<"input last name :";
cin>>list[x].family;
cout<<"input phone number :";
cin>>list[x].phone;
clrscr();
x++;}
void search()
{int i,num,p;
char text[20];
cout<<"search by name(1) or tell number(2):";
cin>>p;
if(p==1)
{
cout<<"name:";
cin>>text;
for(i=1;i<=x;i++)
{
if (strcmpi(text,list[i].name)==0)
{
cout<<list[i].name<<endl;
cout<<list[i].family<<endl;
cout<<list[i].phone<<endl;
}
else cout<<"this name not here"<<endl;
}
}
else
if (p==2)
{
cout<<"tell number:";
cin>>num;
for(i=1;i<=x;i++)
{
if (num==list[i].phone)
{
cout<<list[i].name<<endl;
cout<<list[i].family<<endl;
cout<<list[i].phone<<endl;
}
else cout<<"this number not here"<<endl;
}
}
else cout<<"sorry"<<endl;
}
void list_()
{
int i;
for(i=1;i<x;i++)
{cout<<"----------------"<<endl;
cout<<"|"<<list[i].name<<"|";
cout<<"|"<<list[i].family<<"|";
cout<<"|"<<list[i].phone<<"|"<<endl;
cout<<"----------------"<<endl;
}
}
void delet()
{
int a,i,j;
cout<<"enter a fhone number for delete:";
cin>>a;
for(i=1;i<=x;i++)
{if (a==list[i].phone)
{for (j=i;j<=x;j++)
{strcpy(list[j+1].name,list[j].name);
strcpy(list[j+1].family,list[j].family);
list[j+1].phone=list[j].phone;
}
}
else
cout<<"this number not here"<<endl;}}
int main()
{
int c,t,i,y;
long f;
while(1)
{
cout<<"1-Add"<<endl;
cout<<"2-Search"<<endl;
cout<<"3-List"<<endl;
cout<<"4-Delete"<<endl;
cout<<"5-Exit"<<endl<<"insert a number then press enter:";
cin>>c;
switch (c){
case 1:
add();
break;
case 2 :
search();
break;
case 3 :
list_();
break;
case 4 :
delet();
break;
case 5 :
return 0;
break;
}
}
getch();
return 0;
}
اشتباه شد
sorry
توی کد شما کافیه جای
ازکد:
cout<<
وجایکد:
printf()
ازکد:
cin >>
استفاده شه. همین.کد:
scanf()
میشه سورس برنامه دفتر تلفن رو بذارید به زبان c
این ارور میده
کامپایل نکردم اگه ارور داشت بگو :
کد:[QUOT]
#include <conio.h>
#include <string.h>
#include <stdio.h>
int x=1;
struct tell{
char name[20];
char family[20];
int phone;
} list[100];
void add()
{if (x>=100)
printf("sory. the fhone book is complete\n");
else
printf("input first name :");
scanf("%s",list[x].name);
printf("input last name :");
scanf("%s",list[x].family);
printf("input phone number :");
scanf("%d",&list[x].phone);
clrscr();
x++;}
void search()
{int i,num,p;
char text[20];
printf("search by name(1) or tell number(2):");
scanf("%d",&p);
if(p==1)
{
printf("name:");
scanf("%s",text);
for(i=1;i<=x;i++)
{
if (strcmpi(text,list[i].name)==0)
{
printf(list[i].name);
printf("\n");
printf(list[i].family);
printf("\n");
printf(list[i].phone);
printf("\n");
}
else printf("this name not here");printf("\n)";
}
}
else
if (p==2)
{
printf("tell number:");
scanf("%d",&num);
for(i=1;i<=x;i++)
{
if (num==list[i].phone)
{
printf(list[i].name);
printf("\n");
printf(list[i].family);
printf("\n");
printf(list[i].phone);
printf("\n");
}
else printf("this number not here");
printf("\n");
}
}
else printf("sorry\n");
}
void list_()
{
int i;
for(i=1;i<x;i++)
{printf("----------------\n");
printf(list[i].name);
printf("\n");
printf(list[i].family);
printf("\n");
printf(list[i].phone);
printf("\n");
}
}
void delet()
{
int a,i,j;
printf("enter a fhone number for delete:");
scanf("%d", &a);
for(i=1;i<=x;i++)
{if (a==list[i].phone)
{for (j=i;j<=x;j++)
{strcpy(list[j+1].name,list[j].name);
strcpy(list[j+1].family,list[j].family);
list[j+1].phone=list[j].phone;
}
}
else
printf("this number not here\n");}}
int main()
{
int c,t,i,y;
long f;
while(1)
{
printf("1-Add\n");
printf("2-Search\n");
printf("3-List\n");
printf("4-Delete\n");
printf("5-Exit\ninsert a number then press enter:");
scanf("%d",&c);
switch (c){
case 1:
add();
break;
case 2 :
search();
break;
case 3 :
list_();
break;
case 4 :
delet();
break;
case 5 :
return 0;
break;
}
}
getch();
return 0;
}
[/QUOTE]
ممنون
روی printf(list[i].phone
ارور میده :41:
يک برنامه مي خوام با خروجي زير با زبانC++
1
2222
333333
44444444
ممنون ميشم.