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

اين الخطأ في هذا الكود؟ تكفون يا شباب محتاج الرد بأسرع وقت ممكن!

بدأه Computer Guy في 28 فبراير 2008 · 13 رد · 988 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

الاخوة الاعزاء

يرجوا إفادتي بالخطأ في هذا الكود:

#include<iostream.h>

#include<math.h>

/* cos example */

#include <stdio.h>

#include <math.h>

#define PI 3.14159265

void main()

{

int number;

int choise;

cout<<"please enter number \n";

cin>>number;

cout<<"1. The square root ? n ."<<endl;

cout<<"2. The inverse ? 1/n. "<<endl;

cout<<"3. The cosine ? cos(n)."<<endl;

cout<<"4. The cube ? n3."<<endl;

cout<<"5. The logarithm base 10 ? log10n."<<endl;

cout<<"please hose one step \n";

cin>>choise;

switch(choise)

{

case 1:

cout<<"the root is "<<sqrt(number)<<endl;

break;

case 2:

cout<<"the inverse is "<<pow(number,0.5)<<endl;

break;

case 3:

cout<<"the cos is "<<cos (number*PI/180);<<endl;

break;

case 4:

cout<<"the cube is "<<pow(number,3)<<endl;

break;

case 5:

cout<<"the log10 is "<<log10 (number)<<endl;

break;

}

}

لمن احاول اعمل له كومبايلر يطلع لي الناتج التالي

[name@host demo3]$ g++ pa33.cpp

pa33.cpp:18: error: `main' must return `int'

pa33.cpp: In function `int main(...)':

pa33.cpp:43: error: expected primary-expression before '<<' token

[name@host demo3]$

والله يوفقكم يا شباب

#2

إكتب return 0 فى أخر ال main

شيل ال ; من النص فى السطر >

cout<<"the cos is "<<cos (number*PI/180);<<endl;

يا ريت تستعمل علامات الأكواد بعد كدة يا أخى حتى تسهل قراءة كودك["code"] و تكتب الكود بتاعك و بعدين تقفلها ["/code"] بدون علامات التنصيص طبعا.

#3

استخدمتها وماضبط يا اخي العزيز ما ادري ليه !

طيب يالغالي ولا عليك امر ناتج cosine يطلع لي غلط في كل مرة احاول ما ادري ليه؟

ممكن تجرب وترد لي خبر ولاعليك امر؟

اطيب التحية,

#4

السلام عليكم فقط بدل التصريح:

int number;

double number;

يضبط معك البرنامج. باذن الله.

tvquran_6.gif

#5

حاولت يالغالي بس ماضبط معي ! :(

مافي حل اخر يالغالي؟

بالتوفيق !

#6

هذا الكود يعمل لدي بدون أخطاء.

#include<iostream>
using namespace std;
#include<math.h>

#define PI 3.14159265
int main()
{
double number;
int choise;
cout<<"please enter number \n";
cin>>number;
cout<<"1. The square root n ."<<endl;
cout<<"2. The inverse 1/n. "<<endl;
cout<<"3. The cosine cos(n)."<<endl;
cout<<"4. The cube n3."<<endl;
cout<<"5. The logarithm base 10 log10n."<<endl;
cout<<"please hose one step \n";
cin>>choise;
switch(choise)
{
case 1:
cout<<"the root is "<<sqrt((number))<<endl;
break;
case 2:
cout<<"the inverse is "<<pow((number),0.5)<<endl;
break;
case 3:
cout<<"the cos is "<<cos ((number)*PI/180)<<endl;
break;
case 4:
cout<<"the cube is "<<pow((number),3)<<endl;
break;
case 5:
cout<<"the log10 is "<<log10 ((number))<<endl;
break;
}
return 0;
}

اذا كنت تستخدم مصرف قديم ابدل السطرين

#include<iostream>
using namespace std;

بالسطر

#include<iostream.h>
tvquran_6.gif

#7

ليه يا أخى ماهو ظبط معايا أهو>

CONSOLE
please enter number

60

1. The square root ? n .

2. The inverse ? 1/n.

3. The cosine ? cos(n).

4. The cube ? n3.

5. The logarithm base 10 ? log10n.

please hose one step

3

the cos is 0.5

و دا الكود >

#include<iostream.h>
#include<math.h>
/* cos example */
#include <stdio.h>
#include <math.h>

#define PI 3.14159265


int main()
{

int number;
int choise;

cout<<"please enter number \n";
cin>>number;

cout<<"1. The square root ? n ."<<endl;
cout<<"2. The inverse ? 1/n. "<<endl;
cout<<"3. The cosine ? cos(n)."<<endl;
cout<<"4. The cube ? n3."<<endl;
cout<<"5. The logarithm base 10 ? log10n."<<endl;
cout<<"please hose one step \n";
cin>>choise;

switch(choise)
{
case 1:
cout<<"the root is "<<sqrt(number)<<endl;
break;
case 2:
cout<<"the inverse is "<<pow(number,0.5)<<endl;
break;
case 3:
cout<<"the cos is "<<cos (number*PI/180)<<endl;
break;
case 4:
cout<<"the cube is "<<pow(number,3)<<endl;
break;
case 5:
cout<<"the log10 is "<<log10 (number)<<endl;
break;

}
return 0;
}

#ههههه عمرك أطول من عمرى يا فهد :D

تم تعديل هذه المشاركة بواسطة Blueteeth في 28 فبراير 2008 في 04:51

#8

يا شباب جربوا cosine 90

ما ادري ليه مش راضي يضبط معي!

اطيب التحية,

#9
اقتباس
جربوا cosine 90

اذا تقصد ما تعطي نتيجه صحيحة فا عتقد ان الدوال تتعامل مع الرديان وليس الدرجة.

tvquran_6.gif

#11

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

اسف لم انتبه لهذا السطر.

cos (number*PI/180)

وهذا معناه انك حولت للدرجه فعلا.

النتيجه تظهر بالفاصله العشريه

قرب لثلاث خانات مثلا:

cout<<fixed <<setprecision(3);

لا تنسى نضيف الهد:

#include<iomanip>
tvquran_6.gif

#12
فهدالشلوي كتب:
السلام عليكم:

اسف لم انتبه لهذا السطر.

cos (number*PI/180)

وهذا معناه انك حولت للدرجه فعلا.

النتيجه تظهر بالفاصله العشريه

قرب لثلاث خانات مثلا:

cout<<fixed <<setprecision(3);

لا تنسى نضيف الهد:

#include<iomanip>

السلام عليكم

هل مطلوب مني اني استبدل الكود الثاني بالكود الاول؟

تحياتي,

#13

السلام عليكم

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

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define PI 3.14159265
int main()
{
double number;
int choise;
cout<<fixed <<setprecision(3); 
cout<<"please enter number \n";
cin>>number;
cout<<"1. The square root n ."<<endl;
cout<<"2. The inverse 1/n. "<<endl;
cout<<"3. The cosine cos(n)."<<endl;
cout<<"4. The cube n3."<<endl;
cout<<"5. The logarithm base 10 log10n."<<endl;
cout<<"please hose one step \n";
cin>>choise;
switch(choise)
{
case 1:
cout<<"the root is "<<sqrt((number))<<endl;
break;
case 2:
cout<<"the inverse is "<<pow((number),0.5)<<endl;
break;
case 3:
cout<<"the cos is "<<(cos ((number*PI)/180))<<endl;
break;
case 4:
cout<<"the cube is "<<pow((number),3)<<endl;
break;
case 5:
cout<<"the log10 is "<<log10 ((number))<<endl;
break;
}
return 0;
}
tvquran_6.gif

#14

تفضل أخي :

void main()

في ++c الدالة main تكون غالبا int و ترجع 0 في الأخير غالبا ،أي أنه نسيت :

return 0;

********************

cout<<"the cos is "<<cos (number*PI/180);<<endl;

عند وضع ; يعني نهاية السطر و بدأ سطر جديد لذا كان عليك أن تقوم بالتالي :

cout<<"the cos is "<<cos (number*PI/180)<<endl;

أو :

cout<<"the cos is "<<cos (number*PI/180);
cout<<endl;

الكود بعد التعديل رغم أنه من المفروض أن تكون قيمة cos(90) هي 0 :

#include <stdio.h>
#include <math.h>
#include <iostream.h>
#define PI 3.1415926535874932384626433832795

int main()
{

double number;
int choise;
cout<<"please enter number \n";
cin>>number;

cout<<"1. The square root ? n2 ."<<endl;
cout<<"2. The inverse ? 1/n. "<<endl;
cout<<"3. The cosine ? cos(n)."<<endl;
cout<<"4. The cube ? n3."<<endl;
cout<<"5. The logarithm base 10 ? log10n."<<endl;
cout<<"please chose one step \n";
cin>>choise;

switch(choise)
{
case 1:
cout<<"the root is "<<sqrt(number)<<endl;
break;
case 2:
cout<<"the inverse is "<<pow(number,0.5)<<endl;
break;
case 3:
cout<<"the cos is "<<cos(number*PI/180)<<endl;
break;
case 4:
cout<<"the cube is "<<pow(number,3)<<endl;
break;
case 5:
cout<<"the log10 is "<<log10(number)<<endl;
break;
}
return 0;
}

''‏اللهم إني أسالك إيمانا دائما وأسألك قلبا خاشعا وأسألك علما ‏نافعا وأسألك يقينا صادقا وأسألك دينا قيما وأسألك العافية من كل ‏بلية''

'‏اللهم أغفر للمؤمنين و المؤمنات و المسلمين و المسلمات الأحياء ‏منهم و الأموات'

www.it-scoop.com

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

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

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

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

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