arkadaşlar aşağıdaki kodu yazıyorum label 3 de bir sorun var sıralanmış array ı yanlış yazdırıyor. Deli oldum lütfen yardım eder misiniz? Bu şekilde hata alıyorum. Sondaki 3 tane fazladan olmayan rakam çıkıyo biryerlerden Başka hata olmaması lazım ama bi incelerseniz çok sevinirim. Tıkandım. Yardım edin lütfen.
/* Task: Write a program with a menu for choosing the next functions: */ /* a) Function enters an integer array P[k], k<25; */ /* b) Function that finds the elements, which belong to a define interval [a,b] and save them in a new array PN; */ /* c) Function that sorts this array (PN) descending. */
#include <iostream.h> #include <conio.h> int main() { int P[25],i,N,PN[25],j,tempi,temps,k=1,l=2,m=3,a,b,p,r,s; /*First menu*/ label1: cout<<"\n\t\tMenu"; cout<<"\n\t 1. Enter an array \n"; cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval (it needs 1st)\n"; cout<<"\t 3. Sort the new interval (it needs 1st and 2nd)\n"; cout<<"Your choise:"; cin>>k; if(k>=1 && k<=3) { switch (k) { case 1: cout<<"\n\tYou have chosen 1. Enter an array"; do{cout<<"\n How many elements you have:"; cin>>N;} while(N<1||N>25); for(i=0;i<N;i++) {cout<<"\n Input "<<i+1<<" number:"; cin>>P[i];}break; case 2: cout<<"\nFirst you must enter the array\n";goto label1;break; case 3: cout<<"\nFirst you must enter the array\n";goto label1;break; } } else goto label1; label2: cout<<"\n\t\tMenu"; cout<<"\n\t 1. Enter an array (done)\n"; cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval\n"; cout<<"\t 3. Sort the new interval (it needs 2nd)\n"; cout<<"Your choise:"; cin>>l; if(l>=1 && l<=3) { switch (l) { case 1: cout<<"\n\tYou have chosen 1. Enter an array but this has already done"; case 2: cout<<"\n\tStarting the next step\n"; cout<<"Enter the interval [a,b]"; cout<<"\na="; cin>>a; cout<<"\nb="; cin>>b; if(a>b) {tempi=a;a=b;b=tempi;} for(j=0,i=0;i<N;i++) { p=P[i]; if(p>a && p<b) {PN[j]=P[i];j++;} } cout<<"\n New array:"; for(i=0;i<j;i++) cout<<PN[i]<<" ";break; case 3: cout<<"\nYou hadn't done the second step, yet.\n";goto label2;break; } } else goto label2; label3: cout<<"\n\t\tMenu"; cout<<"\n\t 1. Enter an array (done)\n"; cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval (done)\n"; cout<<"\t 3. Sort the new interval\n"; cout<<"Your choise:"; cin>>m; if(m>=1 && m<=3) { switch (m) { case 1: cout<<"\n\tYou have chosen 1. Enter an array but this has already done"; case 2: cout<<"\n\tYou have chosen 2. Interval control but this has already done\n"; case 3: cout<<"\nStarting the next step\n"; for(s=0;s<i;s++) for(r=s+1;r<i;r++) if(PN[s]<PN[r]) { temps=PN[s]; PN[s]=PN[r]; PN[r]=temps; } cout<<"\n Sorted Array: "; for(i=0;i<N;i++) cout<<PN[i]<<" "; } } else goto label3; cout<<"\nthe end"; getch(); return 0; }
DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.
Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.
Tamamdır beyler gece gece görememişim çok salakça bi hata var. Düzenlemeleri yapıp buraya da yollarım belki birinin işine yarar ;) kolay gelsin..
Edit: Düzeltmeler tamam buyrun arklar..
[code] /* Task: Write a program with a menu for choosing the next functions: */ /* a) Function enters an integer array P[k], k<25; */ /* b) Function that finds the elements, which belong to a define interval [a,b] and save them in a new array PN; */ /* c) Function that sorts this array (PN) descending. */
#include <iostream.h> #include <conio.h> int main() { int P[25],i,N,PN[25],j,tempi,temps,k=1,l=2,m=3,a,b,p,r; /* First menu */ label1: cout<<"\n\t\tMenu"; cout<<"\n\t 1. Enter an array \n"; cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval (it needs 1st)\n"; cout<<"\t 3. Sort the new interval (it needs 1st and 2nd)\n"; /* Entering the selection from the menu */ cout<<"Your choise:"; cin>>k; /* Control the selection is true or false */ /* If it is false it must be reentered */ if(k>=1 && k<=3) { switch (k) { case 1: cout<<"\n\tStarting first step:"; /* Taking the information about how many elements will be used */ do{cout<<"\n How many elements you have:"; cin>>N;} while(N<1||N>25); /* Entering each elements to the array */ for(i=0;i<N;i++) { cout<<"\n Input "<<i+1<<" number:"; cin>>P; }break; case 2: cout<<"\nFirst you must enter the array\n";goto label1;break; case 3: cout<<"\nFirst you must enter the array\n";goto label1;break; } } /* if the menu selection is false user jumps to the begining of the first menu */ else goto label1; /* The end of the first menu */ /* Second menu */ label2: cout<<"\n\t\tMenu"; cout<<"\n\t 1. Enter an array (done)\n"; cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval\n"; cout<<"\t 3. Sort the new interval (it needs 2nd)\n"; /* Entering the selection from the menu */ cout<<"Your choise:"; cin>>l; /* Control the selection is true or false */ /* If it is false it must be reentered */ if(l>=1 && l<=3) { switch (l) { /* If user try to enter selection 1 it is continue from selection 2*/ /* Because selection 1 has already done */ case 1: cout<<"\n\tYou have chosen 1. Enter an array but this has already done"; case 2: cout<<"\n\tStarting the second step\n"; /* Taking the informaion about interval */ cout<<"Enter the interval [a,b]"; cout<<"\na="; cin>>a; cout<<"\nb="; cin>>b; /* If the interval isn't in order it must be get order */ if(a>b) {tempi=a;a=b;b=tempi;} /* After ordering step finding elements which belongs to the interval */ for(j=0,i=0;i<N;i++) { p=P; if(p>a && p<b) {PN[j]=P;j++;} } /* Printing the new array */ cout<<"\n New array: "; for(i=0;i<j;i++) cout<<PN<<" ";break; case 3: cout<<"\nYou hadn't done the second step, yet.\n";goto label2;break; } } /* if the menu selection is false user jumps to the begining of the second menu */ else goto label2; /* The end of the second menu */ /* Third menu */ label3: cout<<"\n\t\tMenu"; cout<<"\n\t 1. Enter an array (done)\n"; cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval (done)\n"; cout<<"\t 3. Sort the new interval\n"; /* Entering the selection from the menu */ cout<<"Your choise:"; cin>>m; /* Control the selection is true or false */ /* If it is false it must be reentered */ if(m>=1 && m<=3) { switch (m) { case 1: cout<<"\n\tYou have chosen 1. Enter an array but this has already done"; case 2: cout<<"\n\tYou have chosen 2. Interval control but this has already done\n"; case 3: cout<<"\nStarting the third step\n"; /* Sorting the New array */ for(i=0;i<j-1;i++) for(r=i+1;r<j;r++) if(PN<PN[r]) { temps=PN; PN=PN[r]; PN[r]=temps; } /* Printing the sorted array */ cout<<"\n Sorted Array: "; for(i=0;i<j;i++) cout<<PN<<" "; } } /* if the menu selection is false user jumps to the begining of the third menu */ else goto label3; /* The end of the tird menu */ cout<<"\n\nThe End\n"; /* The end of the program */ getch(); return 0; } [/CODE]
< Bu mesaj bu kişi tarafından değiştirildi CAssassin -- 3 Kasım 2007; 13:21:57 >
Bu şekilde hata alıyorum. Sondaki 3 tane fazladan olmayan rakam çıkıyo biryerlerden
Başka hata olmaması lazım ama bi incelerseniz çok sevinirim.
Tıkandım. Yardım edin lütfen.
< Resime gitmek için tıklayın >
DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.
Üye Ol Şimdi DeğilÜye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.
< Bu mesaj bu kişi tarafından değiştirildi CAssassin -- 3 Kasım 2007; 4:44:54 >