الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

استفسار عن كيفية استخدم دالة Goto مع هذا الكود ؟

بدأه FunnyWolF في 29 أكتوبر 2008 · 6 رد · 908 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــة

عندي استفسار عن كيفية استخدام دالة goto لأني ابي البرنامج يعيد نفسه اذا ادخل المستخدم قيمة 1 للمتغير a في اول البرنامج

#include <stdio.h>
main ()
{
again; /*I want to come back here and do the code again*/
int a;
printf "do you want have FUN ? you are in step 1\n";
printf "please type 1 for yes or 2 for no\n";
scanf ("%d", a);
if (a=1)
 {
 int b;
 printf "do you want a quick fun? you are in step 2\n";
 printf "please type 1 for yes or 2 for no\n";
 scanf ("%d", b);
 if (b=1)
  {printf "you like having fun quickly. you are in step 4\n";
  }
 else
  {
  int c;
  printf "ok,do you like have fun with people or alone? you are in step 3\n";
  printf "please type 1 for with people or 2 for alone\n";
  scan ("%d",c);
  if (c=1)
   {
   printf "you have chosen the good choice, you are in step 5\n";
   }
  else
   {
   printf "why you like have fun alone? you are in step 6\n";
   }
  printf " having fun with people is better. you are in step 7\n";
  } 
 printf "OK, take some FUN and enjoy : ) , you are in step 8\n";
 if (a=1) then goto again; /* I want to go back to the first point in this program when a=1 */
 }
printf "ok, the program finish, you are in step 9";
}

وشكرا

#2

يمكن بهذا الشكل:

  1. #include <stdio.h>
  2. int main ()
  3. {
  4. again: /*I want to come back here and do the code again*/
  5.  
  6. int a;
  7.  
  8. printf("do you want have FUN ? you are in step 1n");
  9. printf("please type 1 for yes or 2 for non");
  10.  
  11. scanf("%d", &a);
  12. if (a==1)
  13. {
  14. int b;
  15.  
  16. printf("do you want a quick fun? you are in step 2n");
  17. printf("please type 1 for yes or 2 for non");
  18.  
  19. scanf("%d", &b);
  20. if (b==1)
  21. {
  22. printf("you like having fun quickly. you are in step 4n");
  23. }
  24. else
  25. {
  26. int c;
  27.  
  28. printf("ok,do you like have fun with people or alone? you are in step 3n");
  29. printf("please type 1 for with people or 2 for alonen");
  30.  
  31. scanf("%d", &c);
  32. if (c==1)
  33. {
  34. printf("you have chosen the good choice, you are in step 5n");
  35. }
  36. else
  37. {
  38. printf("why you like have fun alone? you are in step 6n");
  39. }
  40. printf(" having fun with people is better. you are in step 7n");
  41. }
  42.  
  43. printf("OK, take some FUN and enjoy : ) , you are in step 8n");
  44. if (a==1)
  45. goto again; /* I want to go back to the first point in this program when a=1 */
  46. }
  47. printf("ok, the program finish, you are in step 9");
  48.  
  49. return 0;
  50. }
  51.  

والأفضل بهذا الشكل
  1. int main ()
  2. {
  3. int a;
  4.  
  5. printf("do you want have FUN ? you are in step 1n");
  6. printf("please type 1 for yes or 2 for non");
  7.  
  8. scanf("%d", &a);
  9. while (a==1)
  10. {
  11. int b;
  12.  
  13. printf("do you want a quick fun? you are in step 2n");
  14. printf("please type 1 for yes or 2 for non");
  15.  
  16. scanf("%d", &b);
  17. if (b==1)
  18. {
  19. printf("you like having fun quickly. you are in step 4n");
  20. }
  21. else
  22. {
  23. int c;
  24.  
  25. printf("ok,do you like have fun with people or alone? you are in step 3n");
  26. printf("please type 1 for with people or 2 for alonen");
  27.  
  28. scanf("%d", &c);
  29. if (c==1)
  30. {
  31. printf("you have chosen the good choice, you are in step 5n");
  32. }
  33. else
  34. {
  35. printf("why you like have fun alone? you are in step 6n");
  36. }
  37. printf(" having fun with people is better. you are in step 7n");
  38. }
  39.  
  40. printf("OK, take some FUN and enjoy : ) , you are in step 8n");
  41. }
  42. printf("ok, the program finish, you are in step 9");
  43.  
  44. return 0;
  45. }
  46.  

#3

اخي, الف شكر لمساعدتك ... لكن يعطيني غلط بعد كلمة again: ويقلي في حاجه ناقصة قبل int a ؟ فما ادري اش المشكله ؟؟؟؟

#4

السلام عليكــم ورحمـة الله وبركاتــة

هذا بالنسبه لتعديل اكواد الاخ دحدوح

بغيت الونها مثل دحدوح ماعرفت هههههههههههه

واسف دحدوح على اللقافه بس كنت طفشان :D

 #include <iostream>
 #include <stdio.h>

 using namespace std;


	   int main ()

	   {

	   int a;



	   printf("do you want have FUN ? you are in step 1\n");

	   printf("please type 1 for yes or 2 for no\n");



	   scanf("%d", &a);

	   while (a==1)

	   {

	   int b;



	   printf("do you want a quick fun? you are in step 2\n");

	   printf("please type 1 for yes or 2 for no\n");



	   scanf("%d", &b);

	   if (b==1)

	   {

	   printf("you like having fun quickly. you are in step 4\n");

	   }

	   else

	   {

	   int c;



	   printf("ok,do you like have fun with people or alone? you are in step 3\n");

	   printf("please type 1 for with people or 2 for alone\n");



	   scanf("%d", &c);

	   if (c==1)

	   {

	   printf("you have chosen the good choice, you are in step 5\n");

	   }

	   else

	   {

	   printf("why you like have fun alone? you are in step 6\n");

	   }

	   printf(" having fun with people is better. you are in step 7\n");

	   }




	   printf("OK, take some FUN and enjoy : ) , you are in step 8\n");

	   }

	   printf("ok, the program finish, you are in step 9");



	   return 0;

	   }

الكود الثاني

 #include <iostream>
 #include <stdio.h>

 using namespace std;

 int main ()

 {

 again: /*I want to come back here and do the code again*/



 int a;



 printf("do you want have FUN ? you are in step 1\n");

 printf("please type 1 for yes or 2 for no\n");



 scanf("%d", &a);

 if (a==1)

 {

 int b;



 printf("do you want a quick fun? you are in step 2\n");

 printf("please type 1 for yes or 2 for no\n");



 scanf("%d", &b);

 if (b==1)

 {

 printf("you like having fun quickly. you are in step 4\n");

 }

 else

 {

 int c;



 printf("ok,do you like have fun with people or alone? you are in step 3\n");

 printf("please type 1 for with people or 2 for alone\n");



 scanf("%d", &c);

 if (c==1)

 {

 printf("you have chosen the good choice, you are in step 5\n");

 }

 else

 {

 printf("why you like have fun alone? you are in step 6\n");

 }

 printf(" having fun with people is better. you are in step 7\n");

 }



 printf("OK, take some FUN and enjoy : ) , you are in step 8\n");

 if (a==1)

 goto again; /* I want to go back to the first point in this program when a=1 */

 }

 printf("ok, the program finish, you are in step 9");



 return 0;

 }
#5

الخطأ الوحيد اللي كان عندك هو إنك إستخدمت الفارزه المنقوطه بعد again;

والصحيح again:

بس :)


HeartOutputStream myHeart;
OutputStream myHeartOutStream;

myHeartOutStream = MAllaw.getHeart().getOutputStream();
myHeart = new HeartOutputStream(myHeartOutStream);

while(myHeart.isStillBeating())
myHeart.write("I ♥ Java");

#6

السلام عليكــم ورحمـة الله وبركاتــة

ياشباب الله يعطيكم الف عافيه,مقدر تعاونكم

لكن هالغلط لحس مخي والله هذه الرساله اللي يعطيني

In function 'main,:
expected expression before 'int'

الان again هذه هل يحتاج مني اعرفها؟

هل بعد again احط اقواس او شي؟

انا متأكد اني استخدمت النقطتين فوق بعض مو الفاصله المنقوطه لكن برضو خطأ لحس مخي والله

#7

ياهوووووووووووووووووووووووووووووو

ابشركم خلاص, حطيت اقواس للداله again وكل شي ضبط واشتغل البرنامج ميه ميه

الله يعطيكم العافيه كلــــــــــــــــــــــــــــــــــــــــــــكم وما قصرتو

:D

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…