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

مساعده في C# "خطأ في برنامج بسيط"

مغلق
بدأه lifejustice في 18 يوليو 2003 · 6 رد · 871 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم :

انا لسه مبتدأ في c# واجهتني مشكله فقلت ان شاء الله تحلولي اياها :

بدي اعمل برنامج كالتالي ( اسف ان كان بالانجليزي ولكن لانه مصطلجات علميه فلا يهم ) :

Write an application that inputs from the user the radius of a circle and prints the circle`s diameter ,circumference and area . Use the following formulas :(r is radius ):

( في اشاره الpi او ط في العربي مو عارف اكتبها فبكتبها على شكل 22/7 وانتوا تصرفوا :D )

diameter = 2*r

circumference = 2*22/7*r

area = 22/7*r*r

كتبت الكود كما اعرف وهيه :

using System;



namespace ConsoleApplication14

{

	/// <summary>

	/// Summary description for Class1.

	/// </summary>

	class Class1

	{

  /// <summary>

  /// The main entry point for the application.

  /// </summary>

  [STAThread]

  static void Main(string[] args)

  {

 	 //

 	 // TODO: Add code to start application here

 	 //



 	 string radius;



 	 int diameter,

    circumference,

    area;



 	 Console.Write ( " Please Enter The Radius of Your Circle : " );

 	 radius = Console.ReadLine ();



 	 diameter = Int32.Parse (radius);

 	 circumference = Int32.Parse (radius);

 	 area = Int32.Parse (radius );



 	 diameter = 2 * radius;

 	 circumference = (2) * (22/7)*(radius);

 	 area = (22/7) * (radius * radius);



 	 Console.WriteLine (" The diameter is {0}.", diameter);



 	 Console.WriteLine ( " The circumference is {0}.", circumference);



 	 Console.WriteLine ( " The area is {0}.", area );



  }

	}

}

وكان عندي الخطأ انه :

The Operator * cannot be applied to operands of type "int" and "string".

شو العمل ؟؟؟

بانتظار الاجابه؟؟؟؟

#2

وينكم شباب ؟؟؟؟ يعني البرنامج جدا بسيط؟؟؟؟ يعني ما في حدا يساعد؟؟؟

#3

السلام عليكم ...

أخي الكريم لديك خطأ بسيط جداً

في الجزء من الكود التالي الذي كتبته أنت يجود الخطأ

diameter = 2 * radius;
			circumference = (2) * (22/7)*(radius) ;
			area = (22/7) * (radius * radius);

طبعاً التعريف radius من نوع string يعني ما بيتقبل عمليات الحساب

لهذا عليك أن تعرف تعريف أخر من نوع int وتضعه بدل التعريف radius

وشكراً(f)

If you think yourself that you are nobody, you should go somewhere to find yourself

#4

للاسف اخي لم افهم عليك يا ريت تفصيل اكتر باعاده كتابه الكود الصحيح وشكرا لك.

#5

السلام عليكم

diameter =  2* Int32.Parse(radious);

كمل الباقي

#6
using System;

namespace ConsoleApplication14
{
	/// 
	/// Summary description for Class1.
	/// 
	class Class1
	{
		/// 
		/// The main entry point for the application.
		/// 
		[STAThread]
		static void Main(string[] args)
		{
			//
			// TODO: Add code to start application here
			//

			string radius;
			int diameter , circumference , area , radius2 ;

			Console.Write ( " Please Enter The Radius of Your Circle : " );
			radius = Console.ReadLine () ;

			radius2 = Int32.Parse  ( radius ) ;

			diameter = 2 * radius2;
			circumference = (2) * (22/7)*(radius2) ;
			area = (22/7) * (radius2 * radius2);

			Console.WriteLine (" The diameter is {0}.", diameter);
			Console.WriteLine ( " The circumference is {0}.", circumference);
			Console.WriteLine ( " The area is {0}.", area ) ;

		}
	}

}

أخي دقق في الي انحدف ولي ما نحدف ولي أنضاف ولي ما نضاف :)

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

If you think yourself that you are nobody, you should go somewhere to find yourself

#7

شكرا لك اخي الشبح على اهتمامك مع ان الاجابه جاءت متاخره قليلا ;)

هذا الموضوع مغلق.

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