פורסם 2006 בינואר 2419 שנים #include <iostream.h>#include <conio.h>class car { public: void operate(int a); };int main() { car toyota; int a; main1: system("cls"); menu: cout<<"what do you want to do now?\n(1)brake\n(2)pick a run\n"; cout<<"\n"; cin>>a; if(a!=1 && a!=2){cout<<"press a number between 1-2"; goto menu;} if(a=1) toyota.operate(1); else toyota.operate(2); return 0;}void car::operate(int a) { if(a=1){cout<<"zzzzzzzzzzzzzzzzzz";getch();} if(a=2){cout<<"hhhhannnnnnnn hhhannnnnnnn";getch();} }מה הבעיה בקוד הזה בעצם?תלחצו 1 ו-2 ותבינו
פורסם 2006 בינואר 2419 שנים void car::operate(int a) { if(a[b]==[/b]1){cout<<"zzzzzzzzzzzzzzzzzz";getch();} if(a[b]==[/b]2){cout<<"hhhhannnnnnnn hhhannnnnnnn";getch();} }מה הבעיה לעזאזלתלחצו 1 ו-2ותראו ותבינואא, כן, ותרגיע קצת עם כל פוסט לעזאזל וכו'...
פורסם 2006 בינואר 2519 שנים מחבר חחחחחחחחחח אחילא אמרתי את זה לכםיענו שהקוד הזה בסדר אבל לא פועל חחחחחחוסליחה אם גרמתי לספקותותודה רבה על העזרהפשוט אני מורגל מ perl
פורסם 2006 בינואר 2719 שנים עוד משהו קטן (מצטער להקפיץ, אבל זה חשוב):אל תשתמש ב-gotoלעולם.שימוש ב-goto מראה על תכנון לקוי של התכנית.
פורסם 2006 בינואר 2719 שנים מחבר אם לא הייתי עושה את זהזה היה יוצא מהתכניתבמקרה שלנוהמכונית הייתה נכבתמה עשינו בזה?אני רוצה שזה אחרי פעולה יחזור לתכנית הרגילה דרך אגב כבר תיקנתי את הקוד ועשיתי שינויים ליעילות וקצת צבע#include <iostream.h>#include <conio.h>class car { public: void operate(int a); };int main() { car toyota; int a; main: a==0; system("cls"); system("color 4"); cout<<"\twhat do you want to do now?\n\t(1)brake\n\t(2)pick a run\n\t(3)exit\n\t"; cout<<"\n"; cin>>a; if(a!=1 && a!=2 && a!=3){cout<<"press a number between 1-3";getch(); goto main;} if(a==3){return 0;} toyota.operate(a); goto main; return 0;} void car::operate(int a) { if(a==1){cout<<"zzzzzzzzzzzzzzzzzz";getch();int main();} if(a==2){cout<<"hhhhannnnnnnn hhhannnnnnnn";getch();int main();} else main(); }דרך אגביש פקודה מקבילה ב c++ ל sleep ב c
פורסם 2006 בינואר 2719 שנים קוד יותר טוב לדעתי, תלמד אותו:#include <iostream.h>#include <conio.h>class car{ public: void operate(int a);};int main() { car toyota; int a = 0; while (a != 3) {/* this is wrong, = is an assignment operator (puts the right side value in the left side variable. == is an comparison operator which compares the right side value to the left side value, and returns true if they are the same or false if they arent. */// a==0; a = 0; system("cls"); system("color 4"); cout<<"\twhat do you want to do now?\n\t(1)brake\n\t(2)pick a run\n\t(3)exit\n\t"; cout<<"\n"; cin>>a;// if(a!=1 && a!=2 && a!=3){cout<<"press a number between 1-3";getch(); goto main;}/* this if statment is better, also continue stops the current iteratrion and goes back to the current while or for statement. */ if(a < 1 || a > 3){cout<<"press a number between 1-3";getch(); continue;}// no need for this, the while will take care of this// if(a==3){return 0;} toyota.operate(a); } return 0;}void car::operate(int a){ if(a==1){cout<<"zzzzzzzzzzzzzzzzzz";getch();} else if(a==2){cout<<"hhhhannnnnnnn hhhannnnnnnn";getch();}}ואתה יכול להשתמש ב SLEEP של C גם כן.
פורסם 2006 בינואר 2819 שנים א. באיזה סביבה אתה עובד ? BORLAND ? VISUAL ? GCC ?ב. לא פועל = לא מתקמפל ונותן שגיאה ? או התוכנית עובדת, אבל לא נתקעת כפי שאתה מצפה בחלק הקוד הרללונטי?תלמד לפרט את הבעיה..
פורסם 2006 בינואר 2819 שנים לא מכיר סצפיפית את הסביבה הזו, אבל בדוק האם היא תומכות אולי ב_sleep()usleep()כאשר יתכן והפרמטרים הם זמנים במילי שניות ולא שניות.
פורסם 2006 בינואר 2819 שנים conio.h היא לא חבילה סטנדרטית של C.זה אומר שהיא תלויה מאוד בפלטפורמה שאתה עובד עליה (כלומר זה יהיה שונה בין windows, linux, unix ו-macintosh, וגם שונה בין קומפיילרים שונים).זה גם גורם לכך שיכול להיות שלאותה פונקציה יהיו שמות שונים בפלטפורמות שונות, ופונקציות מסויימות לא יהיו קיימות בפלטפורמות מסוימות בכלל.
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.