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

مثال في السي لا يعمل بعد النسخ و اللصق

بدأه Gigaman في 5 سبتمبر 2008 · 4 رد · 666 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

حاولت ان اتعلم السي عن طريق الموقع ووجدت المثال لا يعمل في

السي

DEV C++

من الموقع التالي

http://www.cprogramming.com/tutorial/lesson5.html

#include <iostream>

using namespace std;

void playgame();
void loadgame();
void playmultiplayer();

int main()
{
  int input;

  cout<<"1. Play game\n";
  cout<<"2. Load game\n";
  cout<<"3. Play multiplayer\n";
  cout<<"4. Exit\n";
  cout<<"Selection: ";
  cin>> input;
  switch ( input ) {
  case 1:			// Note the colon, not a semicolon
	playgame();
	break;
  case 2:			// Note the colon, not a semicolon
	loadgame();
	break;
  case 3:			// Note the colon, not a semicolon
	playmultiplayer();
	break;
  case 4:			// Note the colon, not a semicolon
	cout<<"Thank you for playing!\n";
	break;
  default:			// Note the colon, not a semicolon
	cout<<"Error, bad input, quitting\n";
	break;
  }
  cin.get();
}
post-1386-1223033542.jpg
#2

اخى المشكلة ان الدوال لم يتم تعريفها , بمعنى انه يوجد اسماء الدوال فقط دون محتواها .

This program will compile, but cannot be run until the undefined functions are given bodies, but it serves as a model (albeit simple) for processing input. If you do not understand this then try mentally putting in if statements for the case statements. Default simply skips out of the switch case construction and allows the program to terminate naturally. If you do not like that, then you can make a loop around the whole thing to have it wait for valid input. You could easily make a few small functions if you wish to test the code.

اقرأ اول سطر فى هذا الاقتباس (مكتوب تحت الكود فى الرابط الذى ذكرته)

تم تعديل هذه المشاركة بواسطة Omar Eladel في 5 سبتمبر 2008 في 01:20

#4

أخي الكريم المثال غير المكمل والدوال التي تم تعريفها وإستدعائها غير مكتملة الكتابة فهي مجرد تعريف للدالة وإستدعائها هذا من ناحية

من ناحية الموقع http://www.cprogramming.com/tutorial/lesson5.html

فهو أعطة مثال لكيفية إستخدام switch وهيكلتها في البرنامج حت انهم أسفل المثال كتبوا التالي

This program will compile, but cannot be run until the undefined functions are given bodies

هذا البرنامج سيتم بناءه لكن لن ينف حتى تعرف الدوال ...

فالمثال كان الغرض منه هو كيفية إستعمال switch فقط

#5

كما قال الاخوه فلا شك في ذالك ان الدوال عرفت ولكن لم يحدد ماعليها ان تعمله فهكذا لا ينفذ المترجم الشيفر ه السابقه .. ولكن لكونك مبتدا في هذه اللغه

اردت ان ازيد على الكود السابق لكي يتسنى لك الفهم اكثر ..

  1.  
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void playgame();
  8. void loadgame();
  9. void playmultiplayer();
  10.  
  11. int main()
  12. {
  13. int input;
  14.  
  15. cout<<"1. Play gamen";
  16. cout<<"2. Load gamen";
  17. cout<<"3. Play multiplayern";
  18. cout<<"4. Exitn";
  19. cout<<"Selection: ";
  20. cin>> input;
  21. switch ( input ) {
  22. case 1: // Note the colon, not a semicolon
  23. playgame();
  24. break;
  25. case 2: // Note the colon, not a semicolon
  26. loadgame();
  27. break;
  28. case 3: // Note the colon, not a semicolon
  29. playmultiplayer();
  30. break;
  31. case 4: // Note the colon, not a semicolon
  32. cout<<"Thank you for playing!n";
  33. break;
  34. default: // Note the colon, not a semicolon
  35. cout<<"Error, bad input, quittingn";
  36. break;
  37. }
  38. system("PAUSE");
  39. return 0;
  40. }
  41.  
  42. // نريد ان نضع لها عمل تقوم به
  43.  
  44. void playgame()
  45. {
  46. cout<<"You choise function playgame"<<endl;
  47. }
  48. void loadgame()
  49. {
  50. cout<<"You choise function loadgame"<<endl;
  51. }
  52. void playmultiplayer()
  53. {
  54. cout<<"You choise function playmultiplayer"<<endl;
  55. }
  56.  
  57.  
  58.  

انظر الى الكود الان .. اصبح هناك تعريف لعمل الدوال على الاقل طباعه على الشاشه لاي نص , لانه ليس من المنطق ان تستدعي دالة وهذه الدالة لا تعمل شي ؟ اذا وجب عليك ان تجعلها تقوم بعمل والا لا تستدعها .

تحياتي لك .

سبحان الله , الله اكبر , ولله الحمد

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