פורסם 2006 בספטמבר 2419 שנים מישהו יכול להסביר לי איך אני גורם לתוכנה שיצרתי לחזור על עצמה מתי שהיא מסיימתהנה הקוד עם זה עוזר:#include<iostream.h>void main(){int a,b,c,d,e,f,g,h,i,j;cout<<"if you wont to do the action + please prees 1"<<endl<<"if you wont to do the action - please prees 2"<<endl<<"if you wont to do the action : please prees 3"<<endl<<"if you wont to do the action X please prees 4"<<endl;cin>>a;if (a==1){cout<<"pres the numbers"<<endl;cin>>b>>c;cout<<"--------------------------------the anser---------------------------------------";cout<<b+c;}else if (a==2){cout<<"pres the numbers"<<endl;cin>>d>>e;cout<<"--------------------------------the anser---------------------------------------";cout<<d-e;}else if (a==3){cout<<"pres the numbers"<<endl;cin>>f>>g;cout<<"--------------------------------the anser---------------------------------------";cout<<f/g;}else if (a==4){cout<<"pres the numbers"<<endl;cin>>h>>i;cout<<"--------------------------------the anser---------------------------------------";cout<<h*i;}elsecout<<"did not have opption like this";}
פורסם 2006 בספטמבר 2419 שנים אתה חייב לאפשר לצאת מהתוכנית.אבל אתה יכול לשים את כל קטע הקוד בלולאה שהתנאי עצירה שלה למשל יהיה לחיצה על מקש ה Esc.
פורסם 2006 בספטמבר 2419 שנים מחבר אני התחלתי ללמוד את זה בבצפר ובנתיים אני יודע רק את המשתנה if אני אשמח עם תסביר לי איך
פורסם 2006 בספטמבר 2419 שנים מחבר בסך הכל שאלתי עם אתם יכול להסביר לי קצט על הלולאות אני אודה לכם עם תוכלו לעזור לי
פורסם 2006 בספטמבר 2519 שנים באופן כללי: while (condition){DoWhatYouWant();} במקום המילה condition תשים ערך. אם הוא 0 בסיום תוכן הלולאה, הוא יוצא מהלולאה. במקום DoWhatYouWant() תעשה שם מה שאתה רוצה (למקרה שאתה מתקשה באנגלית ).
פורסם 2006 בספטמבר 2519 שנים מחבר תודה רבה לך עריכה: עם אני רוצה שהוא יחזור חזרה להתחלה איזה תנאי אני שם לו?
פורסם 2006 בספטמבר 2519 שנים את הWHILE אתה צריך לרשום בתחילת התוכנית. בתור תנאי אתה יכול לשים דגל(דגל יכול לקבל 1 מ2 מצבים- 1 או 0) כלשהו שישנה את ערכו כאשר אתה לוחץ על הלחצן E (כמו exit). את כל מה שרשמת בתוכנית עד עכשיו, תשים בתוך הסוגריים המסולסלים.
פורסם 2006 בספטמבר 2519 שנים בעצם, כשהוא מגיע לסוגריים המסולסלים הסוגרים של ה-while, הוא בודק את התנאי של הלולאה. אם הוא אמת (כלומר לא אפס) הוא חוזר לתחילת הלולאה. אם הוא שקר (כלומר אפס) הוא ממשיך ולא חוזר להתחלה.עם זה אתה יכול לשחק איך שאתה רוצה.
פורסם 2006 בספטמבר 2519 שנים מחבר לא שמתי את זה עכשיו ב main והוא כותב לי שגיאה אחרת#include<iostream.h>#include<math.h>while (1)void main(){int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;cout<<"if you wont to do the action + please prees 1"<<endl<<"if you wont to do the action - please prees 2"<<endl<<"if you wont to do the action : please prees 3"<<endl<<"if you wont to do the action X please prees 4"<<endl<<"if you want to do average please prees 5"<<endl<<" if you wont to do sqrt please prees 6"<<endl;cin>>a;if (a==1){cout<<"pres the numbers"<<endl;cin>>b>>c;cout<<"--------------------------------the anser---------------------------------------";cout<<b+c<<endl;cout<<"the programe was created by shai buaron and avichy meiri";}else if (a==2){cout<<"pres the numbers"<<endl;cin>>d>>e;cout<<"--------------------------------the anser---------------------------------------";cout<<d-e<<endl;cout<<"the programe was created by shai buaron and avichy meiri";}else if (a==3){cout<<"pres the numbers"<<endl;cin>>f>>g;cout<<"--------------------------------the anser---------------------------------------";cout<<f/g<<endl<<endl;cout<<"the programe was created by shai buaron and avichy meiri";}else if (a==4){cout<<"pres the numbers"<<endl;cin>>h>>i;cout<<"--------------------------------the anser---------------------------------------";cout<<h*i<<endl<<endl;cout<<"the programe was created by shai buaron and avichy meiri";}else if (a==6){float a,b,c;cout<<"Write 'a' of the equation"<<endl;cin>>a;cout<<"Write 'b' of the equation"<<endl;cin>>b;cout<<"Write 'c' of the equation"<<endl;cin>>c;cout<<"--------------------------------the anser---------------------------------------";cout<<"X1=";cout<<(-b+sqrt(b*b-4*a*c))/(2*a)<<endl;cout<<"X2=";cout<<(-b-sqrt(b*b-4*a*c))/(2*a)<<endl<<endl;cout<<"the programe was created by shai buaron and avichy meiri";}else if (a==5){cout<<"between how many numbers you want to do the action"<<endl;cin>>j;}else{cout<<"didn't have opption like this"<<endl;}if (j==2){cout<<"you do avvarage between 2 numbers please preese them"<<endl;cin>>k>>l;cout<<"--------------------------------the anser---------------------------------------";cout<<(k+l)/2;}else if (j==3){cout<<"you do avvarage between 3 numbers please preese them"<<endl;cin>>m>>n>>o;cout<<"--------------------------------the anser---------------------------------------";cout<<(m+n+o)/3;}else if (j==4){cout<<"you do avvarage between 4 numbers please preese them"<<endl;cin>>b>>c>>d>>e;cout<<"--------------------------------the anser---------------------------------------";cout<<(b+c+d+e)/4;}else if (j==5){cout<<"you do avvarage between 5 numbers please preese them"<<endl;cin>>b>>c>>d>>e>>f;cout<<"--------------------------------the anser---------------------------------------";cout<<(b+c+d+e+f)/5;}else if (j==6){cout<<"you do avvarage between 6 numbers please preese them"<<endl;cin>>b>>c>>d>>e>>f>>g;cout<<"--------------------------------the anser---------------------------------------";cout<<(b+c+d+e+f+g)/6;}else if (j==7){cout<<"you do avvarage between 7 numbers please preese them"<<endl;cin>>b>>c>>d>>e>>f>>g>>h;cout<<"--------------------------------the anser---------------------------------------";cout<<(b+c+d+e+f+g+h)/7;}else{cout<<"didn't have opption like this"<<endl;return(1);}}
פורסם 2006 בספטמבר 2519 שנים טוב, קודם כל, בוא נעשה הפרדה.הפונקציה main() היא הפונקציה הראשית של כל תוכנית, והיא לא נמצאת בתוך שום דבר - כולל לא לולאת while.דבר שני, עשית while(1) שזה אומר, תכנית שלא מסתיימת אף פעם. אני לא בטוח שלזה התכוונת...בקיצור, בתוך ה-main תקיף את הכל בעוד סוגריים מסולסלים, ולפניהם תכתוב while(condition) כאשר רצוי שהcondition יהיה משתנה, כדי שיהיה סיכוי שהתכנית תסתיים מתישהו.
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.