مي بخشي آخر جواب چاپ نشده بود:
کد:Sum of A's Goals:
sum=0;
for(j=0;j<5;j++)
sum=sum+goal[0][j];
Printable View
مي بخشي آخر جواب چاپ نشده بود:
کد:Sum of A's Goals:
sum=0;
for(j=0;j<5;j++)
sum=sum+goal[0][j];
:11:ممنون شرلوک عزیز !!
من کد برنامه رو بازهم ادامه دادم و به جایی رسیدم که مربوط به تحلیل بازیهای هرتیم هست !!
البته برای دوتا تیم A و تیم B فعلا !!:31:
حالا یه زحمتی که برای شما دارم اینه که :کد:#include <iostream.h>
#include <conio.h>
void main()
{
char team[5][15];
int counter[20]={0};
int goal[5][5];
int i,j;
cout<<"Enter five teams"<<"\n";
for( i=0;i<5;i++)
cin>>team[i];
cout<<endl;
for( i=0;i<5;i++)
for( j=i;j<5;j++)
if(i!=j )
cout<<team[i]<<" "<<team[j]<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(i!=j){
cout<<"how many goals has "<<team[i]<<" scored to "<<team[j]<<"?";
cin>>goal[i][j];
}
cout<<"the chart of results is\n";
for(i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(i!=j)
cout<<team[i]<<" "<<goal[i][j]<<" **and** "<<team[j]<<" "<<goal[j][i]<<endl;
}
cout<<"for team"<<team[0][0]<<"\n";// first team
cout<<"the number of scored goals" <<" is "<<goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[1][0]+goal[2][0]+goal[3][0]+goal[4][0]<<endl;
for(i=0;i<5;i++)
if(goal[0][i]> goal[i][0])
counter[0] ++;
cout<<"team "<<team[0][0]<<" won the football match "<<counter[0]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]< goal[i][0])
counter[1]++;
cout<<"team "<<team[0][0]<<" lost the football match "<<counter[1]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]==goal[i][0])
counter[2] ++;
cout<<"team"<<team[0][0]<<"got the same result for "<< counter[2]-1<<" times\n";//end of operation for first team
cout<<"for team"<<team[1][0]<<"\n";//team B
cout<<"the number of scored goals" <<" is "<<goal[1][0]+goal[1][2]+goal[1][3]+goal[1][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][1]+goal[2][1]+goal[3][1]+goal[4][1]<<endl;
for(i=0;i<5;i++)
if(goal[1][i]> goal[i][1])
counter[4] ++;
cout<<"team "<<team[1][0]<<" won the football match "<<counter[4]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]< goal[i][1])
counter[5]++;
cout<<"team "<<team[1][0]<<" lost the football match "<<counter[5]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]==goal[i][1])
counter[6] ++;
cout<<"team "<<team[1][0]<<"got the same result for "<< counter[6]-1<<" times\n";
}
اولا این برنامه براحتی کامپایل و اجرا میشه !! از شما تمنا دارم یه بار هم شما این برنامه رو کامپایل و اجرا کنید و ببینید چجوریه !!
دوم اینکه دیشب متوجه شدم این برنامه تو قسمت آخری که مربوط به تحلیل نتایج هر تیم هست یه مشکلی داره و اون اینه که اسم تیم حتما باید تک حرفی (( فقط یک حرف مثل A )) باشه و مثلا اگه اسم تیم رو pirozi وارد کنم فقط کلمه p اون وارد میشه !!
چند بار خواستم تو بالای برنامه هدر فایل srting.h رو اضافه کنم و اط دستور strcat آرایه های سطر اول آرایه دوبعدی
char team[5][15] رو با هم بگیرم تا هم بتونم اسم تک حرفی رو بدرستی چاپ کنم و هم اسم تیم چند حرفی رو !! ولی گفتم با شما هم یه مشورتی بکنم بد نیست !!:31:
برای اینکه بیشتر متوجه منظورم بشوید برنامه رو اجرا کنید و اینبار بجای اسم تیم اسمهای فینگیلیسی پرسپولیس و استقلال و پاس و ساپیا و سپاهان رو وارد کنید و به خطوط آخر خروجی برنامه که اسم تیم دراونجا ظاهر میشه توجه کنید !! میبینید که مثلا برای تیم pass فقط کلمه p چاپ میشه !!
تا همین الان هم کلی بمن کمک کردیدو منو شرمنده محبتتون کردید !!:11: :40:
واقعا نسبت به بنده لطف دارید:10:
با سلام مجددو عرض خسته نباشي،
نه! لازم نيست اين همه زحمت بكشي .خود C اين زحمت را برايت مي كشد.حالا چه جوري؟
همانطور كه مي بينيم نام تيمها در يك ماتريس 15*5 به نام team ذخيره مي شود.خوب در هر حانه اين ماتريس تنها يك حرف قرارداده مي شود. پس وقتي شما مثلا" مي نويسيبرنامه ناچار است يك حرف را چاپ كند.اين تا اينجا خوب راه حل؟کد:team[0][0]
هيچي از برنامه بخواه كه سطر اول ماتريس هرچه بود چاپ كندچه جوري؟با استفاده ار تنها انديس اول ماتريس:20:
کد:#include <iostream.h>
#include <conio.h>
void main()
{
char team[5][15];
int counter[20]={0};
int goal[5][5];
int i,j;
cout<<"Enter five teams"<<"\n";
for( i=0;i<5;i++)
cin>>team[i];
cout<<endl;
for( i=0;i<5;i++)
for( j=i;j<5;j++)
if(i!=j )
cout<<team[i]<<" "<<team[j]<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(i!=j){
cout<<"how many goals has "<<team[i]<<" scored to "<<team[j]<<"?";
cin>>goal[i][j];
}
cout<<"the chart of results is\n";
for(i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(i!=j)
cout<<team[i]<<" "<<goal[i][j]<<" **and** "<<team[j]<<" "<<goal[j][i]<<endl;
}
cout<<"for team "<<team[0]<<"\n";// first team
cout<<"the number of scored goals" <<" is "<<goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[1][0]+goal[2][0]+goal[3][0]+goal[4][0]<<endl;
for(i=0;i<5;i++)
if(goal[0][i]> goal[i][0])
counter[0] ++;
cout<<"team "<<team[0]<<" won the football match "<<counter[0]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]< goal[i][0])
counter[1]++;
cout<<"team "<<team[0]<<" lost the football match "<<counter[1]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]==goal[i][0])
counter[2] ++;
cout<<"team"<<team[0]<<"got the same result for "<< counter[2]-1<<" times\n";//end of operation for first team
cout<<"for team "<<team[1]<<"\n";//team B
cout<<"the number of scored goals" <<" is "<<goal[1][0]+goal[1][2]+goal[1][3]+goal[1][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][1]+goal[2][1]+goal[3][1]+goal[4][1]<<endl;
for(i=0;i<5;i++)
if(goal[1][i]> goal[i][1])
counter[4] ++;
cout<<"team "<<team[1]<<" won the football match "<<counter[4]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]< goal[i][1])
counter[5]++;
cout<<"team "<<team[1]<<" lost the football match "<<counter[5]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]==goal[i][1])
counter[6] ++;
cout<<"team "<<team[1]<<"got the same result for "<< counter[6]-1<<" times\n";
}
بهمين سادگي
در ضمن شمالطف داري ولي خواهشمندم اين همه شرمنده نكن.اين كمك دو طرفه است.پس ممنون مي شوم اگر ...
با تشكر
#include <iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char team[5] [15]; :18:
int result[5][5];
int i=0,j=0;
cout<<"enter five teams"<<"\n";
for(i=0;i<5;i++)
cin>>team[i];
cout<<endl;
i=0,j=0;
for(i=0;i<5;i++)
for(j=i;j<5;j++) {
if (i!=j) {
cout<<team[i]<<" "<<team[j]<<endl;} }
i=0,j=0;
for(i=0;i<5;i++)
for(j=0;j<5;j++){
if(i!=j) {
cout<<"how many goals has "<<team[i]<<" team scored to "<<team[j]<<" team ?";
cin>>result[i][j-1];
if (result[i][j-1]<0){
result[i][j-1]=0 ;
printf("please enter correct score");
j--;
} } }
i=0,j=0;
cout<<"the chart of results is\n";
for(i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(i!=j)
cout<<team[i]<<":"<<result[j][i-1]<<" "<<team[j]<<":"<<result[i][j-1]<<endl;
}
}
in ham code ha neda.shoay
ممنون !!:11:نقل قول:
ولی خیلی وقته که این تیکه از برنامه رو درست کردم و به مراحل بعدی برنامه رسیدیم !! تو پست بعدی میتونید ملاحظه بفرمایید !!
جسارتا برنامه رو بازهم ادامه دادم :31:و بعد از گرفتن اسم تیمها و چاپ جدول مسابقات و گرفتن نتایج تیمها و چاپ جدول نتایج مسابقات و چاپ جدول امتیازات و تعداد گل زده و خورده و تساوی تیمها و امتیاز تیمها (( برد 3 امتیاز و تساوی 1 امتیاز و باخت 1- امتیاز )) برنامه رو با اینجا رسوندم که حدود 180 خط کد نویسی هست !!:18:
حالا میخوام دوتا کار انجام بدم !!کد:#include <iostream.h>
#include <conio.h>
void main()
{
char team[5][15];//used to enter the name of those five teams in this programm
int time[200]={0};
int counter[200]={0};//used to count the time of winnig and losing and saming the games
float cntphnd[200];//counter per one hundred that is used to descibe the percentage of scoring the goals in any minutes of the football match
int goal[5][5];
int mark[200];
int i,j;
cout<<"Enter five teams"<<"\n";
for( i=0;i<5;i++)
for( i=0;i<5;i++)
cin>>team[i];
cout<<endl;
for( i=0;i<5;i++)
for( j=i;j<5;j++)
if(i!=j )
cout<<team[i]<<" "<<team[j]<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(i!=j){
cout<<"how many goals has "<<team[i]<<" scored to "<<team[j]<<"?";
cin>>goal[i][j];
}
cout<<"the chart of results is\n";
for(i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(i!=j)
cout<<team[i]<<" "<<goal[i][j]<<" **and** "<<team[j]<<" "<<goal[j][i];
cout<<endl;
}
cout<<"FOR TEAM "<<"*** "<<team[0]<<"***"<<"\n";// first team
cout<<"the number of scored goals" <<" is "<<goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[1][0]+goal[2][0]+goal[3][0]+goal[4][0]<<endl;
for(i=0;i<5;i++)
if(goal[0][i]> goal[i][0])
counter[0] ++;
cout<<"team "<<team[0]<<" won the football match "<<counter[0]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]< goal[i][0])
counter[1]++;
cout<<"team "<<team[0]<<" lost the football match "<<counter[1]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]==goal[i][0])
counter[2] ++;
cout<<"team "<<team[0]<<"got the same result for "<< counter[2]-1<<" times\n";
mark[0]=(2* counter[0])+counter[1]-counter[2];
cout<<"the score of team "<<team[0]<<" is"<<mark[0];
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"*** "<<team[1]<<"***"<<"\n";//second team
cout<<"the number of scored goals" <<" is "<<goal[1][0]+goal[1][2]+goal[1][3]+goal[1][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][1]+goal[2][1]+goal[3][1]+goal[4][1]<<endl;
for(i=0;i<5;i++)
if(goal[1][i]> goal[i][1])
counter[4] ++;
cout<<"team "<<team[1]<<" won the football match "<<counter[4]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]< goal[i][1])
counter[5]++;
cout<<"team "<<team[1]<<" lost the football match "<<counter[5]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]==goal[i][1])
counter[6] ++;
cout<<"team "<<team[1]<<"got the same result for "<< counter[6]-1<<" times\n";
mark[1]=(2* counter[4])+ counter[5]-counter[6];
cout<<"the score of team "<<team[1]<<" is"<<mark[1];
cout<<endl;//end of operation for second team
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"*** "<<team[2]<<"***"<<"\n";//third team
cout<<"the number of scored goals" <<" is "<<goal[2][3]+goal[2][4]+goal[2][1]+goal[2][0]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][2]+goal[1][2]+goal[3][2]+goal[4][2]<<endl;
for(i=0;i<5;i++)
if(goal[2][i]> goal[i][2])
counter[7] ++;
cout<<"team "<<team[2]<<" won the football match "<<counter[7]<<" times\n";
for(i=0;i<5;i++)
if(goal[2][i]< goal[i][2])
counter[8]++;
cout<<"team "<<team[2]<<" lost the football match "<<counter[8]<<" times\n";
for(i=0;i<5;i++)
if(goal[2][i]==goal[i][1])
counter[9] ++;
cout<<"team "<<team[2]<<"got the same result for "<< counter[9]<<" times\n";
mark[2]=(2*counter[7])+ counter[8]-counter[9];
cout<<"the score of team "<<team[2]<<" is"<<mark[2];
cout<<endl;//end of operaion for third team
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"*** "<<team[3]<<"***"<<"\n";//fourth team
cout<<"the number of scored goals" <<" is "<<goal[3][0]+goal[3][1]+goal[3][2]+goal[3][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][3]+goal[1][3]+goal[2][3]+goal[4][3]<<endl;
for(i=0;i<5;i++)
if(goal[3][i]> goal[i][3])
counter[10] ++;
cout<<"team "<<team[3]<<" won the football match "<<counter[10]<<" times\n";
for(i=0;i<5;i++)
if(goal[3][i]< goal[i][3])
counter[11]++;
cout<<"team "<<team[3]<<" lost the football match "<<counter[11]<<" times\n";
for(i=0;i<5;i++)
if(goal[3][i]==goal[i][3])
counter[12] ++;
cout<<"team "<<team[3]<<"got the same result for "<< counter[12]-1<<" times\n";
mark[3]=(2*counter[10])+counter[11]-counter[12];
cout<<"the mark of team "<<team[3]<<" is"<<mark[3];//end of operation for forth team
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"***"<<team[4]<<"***"<<"\n";//fifth team
cout<<"the number of scored goals" <<" is "<<goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][4]+goal[1][4]+goal[2][4]+goal[3][4]<<endl;
for(i=0;i<5;i++)
if(goal[4][i]> goal[i][4])
counter[13] ++;
cout<<"team "<<team[4]<<" won the football match "<<counter[13]<<" times\n";
for(i=0;i<5;i++)
if(goal[4][i]< goal[i][4])
counter[14]++;
cout<<"team "<<team[4]<<" lost the football match "<<counter[14]<<" times\n";
for(i=0;i<5;i++)
if(goal[4][i]==goal[i][4])
counter[15] ++;
cout<<"team "<<team[4]<<"got the same result for "<< counter[15]-1<<" times\n";
mark[4]=(2* counter[13])+ counter[14]-counter[15];
cout<<"the mark of team "<<team[4]<<" is"<<mark[4];
cout<<endl;//end of operation for fifth team
cout<<endl;
cout<<endl;
cout<<"enter times of scoring the goals of team "<<team[0];
for(i=0;i<(goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]);i++)
{
cin>>time[i];
}
for(i=0;i<(goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]);i++)
if(time[i]>90 || time[i]<0)
cout<<"error of entering the time";
else
{
for(i=0;i<(goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]);i++)
if(0<=time[i] && time[i] <=15)
counter[16]++;
cntphnd[1] = float( (counter[16]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[1]<<" percent of goals of team "<<team[0]<<" scored between 0 and 15 minutes ";
cout<<endl;
if(16<=time[i] && time[i] <=30)
counter[17]++;
cntphnd[2]= float ((counter[17]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[2]<<" percent of goals of team "<<team[0]<<" scored between 16 and 30 minutes";
cout<<endl;
if( 31<= time[i] && time[i] <=45)
counter[18]++;
cntphnd[3]= float (counter[18]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]);
cout<<cntphnd[3]<<" percent of goals of team "<<team[0]<<" scored between 31 and 45 minutes ";
cout<<endl;
if(46<=time[i] && time[i]<=60)
counter[19]++;
cntphnd[4]= float ((counter[19]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[4]<<" pecent of goals of team "<<team[0]<<" scored between 46 and 60 minues ";
cout<<endl;
if(61<=time[i] && time[i]<=75)
counter[20]++;
cntphnd[5]= float ((counter[20]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[5]<<" percent of goals of team "<<team[0]<< "scored between 61 and 75 minutes ";
cout<<endl;
if(76<=time[i] && time[i]<=90)
counter[21]++;
cntphnd[6]=float((counter[21]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[6]<< " percent of goals of team "<<team[0]<<" scored between 76 and 90 minutes ";
cout<<endl;
}
}
اولا تو خطوط اولیه که اون cin رو قرمز کردم و برنامه در اونجا اسم تیمها رو میگیره میخواهم کاری کنم که برنامه بمحض دریافت هرچیزی بجز کاراکتر error بده و برنامه تموم بشه و پیغام بده که باید حتما از حروف استفاده کنید !!
خودم فکر کردم که بیام و یه دستور شرطی if/else بنویسم و در اون لحاظ بکنم که تک تک کاراکتر های ورودی رو از 'a' تا 'z' چک بکنه و هرجا چیز دیگری وارد بشه error بده !! اما راستش دقیق نمیدونم این دستور رو کجا و بین کدوم حلقه ها و دستور های خروجی cout قرار بدم !! این بود که گفتم با شما هم مشورت بکنم !!
دوم اینکه تو انتهای برنامه و اون تیکه ای که قرمز شده و مربوط به دستور cout<<"enter times of scoring the goals of team "<<team[0]; هست قصد دارم به ازای تعداد گل زده شده که قبلا تو برنامه بدست اومده و به تعداد گلها اعدای از صفر تا نود رو بگیرم که معرف دقایق به ثمر رسیدن گلها هست و سپس با استفاده از حلقه for و تقسیم بندی زمان از صفر تا نود به بازه های 15 دقیقه ای تحلیل بکنم که چند درصد گلها در یک ربع اول بازی و چند درصد در یک ربع دوم و چند در صد در یک ربع سوم و به همین ترتیب چند درصد هم در پانزده دقیقه ششم بازی به ثمر رسیدند !! البته آرایه cntphnd که از جنس float هست و نام آن مخفف counter per hundred هست رو برای همین کار ایجاد کردم که تعداد گلهایی رو که مثلا در پانزده دقیقه اول به ثمر رسیده اند رو در صد ضرب بکنه و تقسیم بر تعداد کل گلهای آن تیم که در نود دقیقه بازی به ثمر رسیده اند بکنه و درصد گلهایی که تو پانزده دقیقه اول زده شده اند رو حساب بکنه که البته تو این بخش هم با مشکل مواجه شدم !! چون برنامه براحتی کامپایل و اجرا میشه ولی تو قسمت درصد گلها تو پانزده دقیقه ها فقط عدد صفر رو چاپ میکنه !!!:41: و این منو آزار میده !!:31:
لازم به ذکر هست که آرایه cntphnd رو برای این 200 تایی انتخاب کردم که مثلا اعضای 0 و 1 و 2 و 3 و 4 و 5 این ارایه برای درصد گلهای تیم A در کل بازیها با تیمهای دیگه و اعضای 6 و 7 و8 و9و 10 و11 برای درصد گلهای تیم B در آن شش تا پانزده دقیقه هست و الی آخر !!
خودم خوب میدونم که ظاهر این برنامه به نظر وحشتناک میاد و کمتر کسی رغبت میکنه به طرفش بره !! ولی واقعیت اینه که چیز زیاد سختی نیست و فقط چند تا قلق داره که من بلد نیستم و بخاطر همین هم در دو مورد گفته شده برای وارد کردن اسم تیمها و درصد گلهای تیمها در 6 تا پانزده دقیقه نیاز به کمک شما دارم !!
ممنون میشم اگه یه کمکی هم به من آماتور بکنید !!:11::11::11:
مرC
باسلام،
شماگفتي:
نقل قول:
"جسارتا برنامه رو بازهم ادامه دادم [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ] و بعد از گرفتن اسم تیمها و چاپ جدول مسابقات و گرفتن نتایج تیمها و چاپ جدول نتایج مسابقات و چاپ جدول امتیازات و تعداد گل زده و خورده و تساوی تیمها و امتیاز تیمها (( برد 3 امتیاز و تساوی 1 امتیاز و باخت 1- امتیاز )) برنامه رو با اینجا رسوندم که حدود 180 خط کد نویسی هست !! [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
حالا میخوام دوتا کار انجام بدم !!
اولا تو خطوط اولیه که اون cin رو قرمز کردم و برنامه در اونجا اسم تیمها رو میگیره میخواهم کاری کنم که برنامه بمحض دریافت هرچیزی بجز کاراکتر error بده و برنامه تموم بشه و پیغام بده که باید حتما از حروف استفاده کنید !!
خودم فکر کردم که بیام و یه دستور شرطی if/else بنویسم و در اون لحاظ بکنم که تک تک کاراکتر های ورودی رو از 'a' تا 'z' چک بکنه و هرجا چیز دیگری وارد بشه error بده !! اما راستش دقیق نمیدونم این دستور رو کجا و بین کدوم حلقه ها و دستور های خروجی cout قرار بدم !! این بود که گفتم با شما هم مشورت بکنم !!
دوم اینکه تو انتهای برنامه و اون تیکه ای که قرمز شده و مربوط به دستور cout<<"enter times of scoring the goals of team "<<team[0]; هست قصد دارم به ازای تعداد گل زده شده که قبلا تو برنامه بدست اومده و به تعداد گلها اعدای از صفر تا نود رو بگیرم که معرف دقایق به ثمر رسیدن گلها هست و سپس با استفاده از حلقه for و تقسیم بندی زمان از صفر تا نود به بازه های 15 دقیقه ای تحلیل بکنم که چند درصد گلها در یک ربع اول بازی و چند درصد در یک ربع دوم و چند در صد در یک ربع سوم و به همین ترتیب چند درصد هم در پانزده دقیقه ششم بازی به ثمر رسیدند !! البته آرایه cntphnd که از جنس float هست و نام آن مخفف counter per hundred هست رو برای همین کار ایجاد کردم که تعداد گلهایی رو که مثلا در پانزده دقیقه اول به ثمر رسیده اند رو در صد ضرب بکنه و تقسیم بر تعداد کل گلهای آن تیم که در نود دقیقه بازی به ثمر رسیده اند بکنه و درصد گلهایی که تو پانزده دقیقه اول زده شده اند رو حساب بکنه که البته تو این بخش هم با مشکل مواجه شدم !! چون برنامه براحتی کامپایل و اجرا میشه ولی تو قسمت درصد گلها تو پانزده دقیقه ها فقط عدد صفر رو چاپ میکنه !!! [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ] و این منو آزار میده !! [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
لازم به ذکر هست که آرایه cntphnd رو برای این 200 تایی انتخاب کردم که مثلا اعضای 0 و 1 و 2 و 3 و 4 و 5 این ارایه برای درصد گلهای تیم A در کل بازیها با تیمهای دیگه و اعضای 6 و 7 و8 و9و 10 و11 برای درصد گلهای تیم B در آن شش تا پانزده دقیقه هست و الی آخر !!
خودم خوب میدونم که ظاهر این برنامه به نظر وحشتناک میاد و کمتر کسی رغبت میکنه به طرفش بره !! ولی واقعیت اینه که چیز زیاد سختی نیست و فقط چند تا قلق داره که من بلد نیستم و بخاطر همین هم در دو مورد گفته شده برای وارد کردن اسم تیمها و درصد گلهای تیمها در 6 تا پانزده دقیقه نیاز به کمک شما دارم !!
ممنون میشم اگه یه کمکی هم به من آماتور بکنید !! [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ] [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ] [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
مرC "
يكم كار مشكل شد،چون ما نام تيمها را بصورت پوينتري وارد كرده ايم و طول نامها هم متغير است و تابع strln هم در ++C تعريف نشده،يا بايد ساختار برنامه را تغيير دهيم و كاراكتر كاراكتر اسامي را در يافت كنيم تا طول اسامي در دسترس باشد و يا به نوعي طول هر نام را بدست آوريم.اگر بتواني اين قسمت را حل كني(به طريقي طول هر نامي كه وارد مي شود بدست آيد) تست كاراكتر ويا غير كاراكتر بودن نام كاري ندارد.من فكر مي كنم تو هم فكر كن!
بخش دوم سوالت با تغييرات زير در برنامه حل شد:
کد:#include <iostream.h>
#include <conio.h>
void main()
{
char team[5][15];//used to enter the name of those five teams in this programm
int time[200]={0};
int counter[200]={0};//used to count the time of winnig and losing and saming the games
float cntphnd[200];//counter per one hundred that is used to descibe the percentage of scoring the goals in any minutes of the football match
int goal[5][5];
int mark[200];
int i,j;
cout<<"Enter five teams"<<"\n";
for( i=0;i<5;i++)
for( i=0;i<5;i++)
cin>>team[i];
cout<<endl;
for( i=0;i<5;i++)
for( j=i;j<5;j++)
if(i!=j )
cout<<team[i]<<" "<<team[j]<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(i!=j){
cout<<"how many goals has "<<team[i]<<" scored to "<<team[j]<<"?";
cin>>goal[i][j];
}
cout<<"the chart of results is\n";
for(i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(i!=j)
cout<<team[i]<<" "<<goal[i][j]<<" **and** "<<team[j]<<" "<<goal[j][i];
cout<<endl;
}
cout<<"FOR TEAM "<<"*** "<<team[0]<<"***"<<"\n";// first team
cout<<"the number of scored goals" <<" is "<<goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[1][0]+goal[2][0]+goal[3][0]+goal[4][0]<<endl;
for(i=0;i<5;i++)
if(goal[0][i]> goal[i][0])
counter[0] ++;
cout<<"team "<<team[0]<<" won the football match "<<counter[0]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]< goal[i][0])
counter[1]++;
cout<<"team "<<team[0]<<" lost the football match "<<counter[1]<<" times\n";
for(i=0;i<5;i++)
if(goal[0][i]==goal[i][0])
counter[2] ++;
cout<<"team "<<team[0]<<"got the same result for "<< counter[2]-1<<" times\n";
mark[0]=(2* counter[0])+counter[1]-counter[2];
cout<<"the score of team "<<team[0]<<" is"<<mark[0];
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"*** "<<team[1]<<"***"<<"\n";//second team
cout<<"the number of scored goals" <<" is "<<goal[1][0]+goal[1][2]+goal[1][3]+goal[1][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][1]+goal[2][1]+goal[3][1]+goal[4][1]<<endl;
for(i=0;i<5;i++)
if(goal[1][i]> goal[i][1])
counter[4] ++;
cout<<"team "<<team[1]<<" won the football match "<<counter[4]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]< goal[i][1])
counter[5]++;
cout<<"team "<<team[1]<<" lost the football match "<<counter[5]<<" times\n";
for(i=0;i<5;i++)
if(goal[1][i]==goal[i][1])
counter[6] ++;
cout<<"team "<<team[1]<<"got the same result for "<< counter[6]-1<<" times\n";
mark[1]=(2* counter[4])+ counter[5]-counter[6];
cout<<"the score of team "<<team[1]<<" is"<<mark[1];
cout<<endl;//end of operation for second team
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"*** "<<team[2]<<"***"<<"\n";//third team
cout<<"the number of scored goals" <<" is "<<goal[2][3]+goal[2][4]+goal[2][1]+goal[2][0]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][2]+goal[1][2]+goal[3][2]+goal[4][2]<<endl;
for(i=0;i<5;i++)
if(goal[2][i]> goal[i][2])
counter[7] ++;
cout<<"team "<<team[2]<<" won the football match "<<counter[7]<<" times\n";
for(i=0;i<5;i++)
if(goal[2][i]< goal[i][2])
counter[8]++;
cout<<"team "<<team[2]<<" lost the football match "<<counter[8]<<" times\n";
for(i=0;i<5;i++)
if(goal[2][i]==goal[i][1])
counter[9] ++;
cout<<"team "<<team[2]<<"got the same result for "<< counter[9]<<" times\n";
mark[2]=(2*counter[7])+ counter[8]-counter[9];
cout<<"the score of team "<<team[2]<<" is"<<mark[2];
cout<<endl;//end of operaion for third team
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"*** "<<team[3]<<"***"<<"\n";//fourth team
cout<<"the number of scored goals" <<" is "<<goal[3][0]+goal[3][1]+goal[3][2]+goal[3][4]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][3]+goal[1][3]+goal[2][3]+goal[4][3]<<endl;
for(i=0;i<5;i++)
if(goal[3][i]> goal[i][3])
counter[10] ++;
cout<<"team "<<team[3]<<" won the football match "<<counter[10]<<" times\n";
for(i=0;i<5;i++)
if(goal[3][i]< goal[i][3])
counter[11]++;
cout<<"team "<<team[3]<<" lost the football match "<<counter[11]<<" times\n";
for(i=0;i<5;i++)
if(goal[3][i]==goal[i][3])
counter[12] ++;
cout<<"team "<<team[3]<<"got the same result for "<< counter[12]-1<<" times\n";
mark[3]=(2*counter[10])+counter[11]-counter[12];
cout<<"the mark of team "<<team[3]<<" is"<<mark[3];//end of operation for forth team
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"FOR TEAM "<<"***"<<team[4]<<"***"<<"\n";//fifth team
cout<<"the number of scored goals" <<" is "<<goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]<<endl;
cout<<"the number of recived goals" <<"is "<<goal[0][4]+goal[1][4]+goal[2][4]+goal[3][4]<<endl;
for(i=0;i<5;i++)
if(goal[4][i]> goal[i][4])
counter[13] ++;
cout<<"team "<<team[4]<<" won the football match "<<counter[13]<<" times\n";
for(i=0;i<5;i++)
if(goal[4][i]< goal[i][4])
counter[14]++;
cout<<"team "<<team[4]<<" lost the football match "<<counter[14]<<" times\n";
for(i=0;i<5;i++)
if(goal[4][i]==goal[i][4])
counter[15] ++;
cout<<"team "<<team[4]<<"got the same result for "<< counter[15]-1<<" times\n";
mark[4]=(2* counter[13])+ counter[14]-counter[15];
cout<<"the mark of team "<<team[4]<<" is"<<mark[4];
cout<<endl;//end of operation for fifth team
cout<<endl;
cout<<endl;
cout<<"enter times of scoring the goals of team "<<team[0];
for(i=0;i<(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]);i++)
{
cin>>time[i];
}
for(i=0;i<(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]);i++)
{if(time[i]>90 || time[i]<0)
cout<<"error of entering the time";
else
{if(time[i]>=0 && time[i]<=15)counter[16]++;
if(time[i]>=16 && time[i]<=30)counter[17]++;
if(time[i]>=31 && time[i]<=45)counter[18]++;
if(time[i]>=46 && time[i]<=60)counter[19]++;
if(time[i]>=61 && time[i]<=75)counter[20]++;
if(time[i]>=76 && time[i]<=90)counter[21]++;
}
}
for(i=1;i<7;i++)
cntphnd[i] = float((counter[15+i]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[1]<<" percent of goals of team "<<team[0]<<" scored between 0 and 15 minutes ";
cout<<endl;
cout<<cntphnd[2]<<" percent of goals of team "<<team[0]<<" scored between 16 and 30 minutes";
cout<<endl;
cout<<cntphnd[3]<<" percent of goals of team "<<team[0]<<" scored between 31 and 45 minutes ";
cout<<endl;
cout<<cntphnd[4]<<" pecent of goals of team "<<team[0]<<" scored between 46 and 60 minues ";
cout<<endl;
cout<<cntphnd[5]<<" percent of goals of team "<<team[0]<< "scored between 61 and 75 minutes ";
cout<<endl;
cout<<cntphnd[6]<< " percent of goals of team "<<team[0]<<" scored between 76 and 90 minutes ";
cout<<endl;
}
يه بررسي بكن تا بعد
سلام و عرض ادب !!:20:
کد برنامه رو با چند تا تغییر ساده تر کردم و خوانایی اون رو افزایش دادم که بصورت زیر دراومد با این فرض که اینبار تو قسمت امتیاز دهی به تیمها تعداد برد رو 3 امتیاز و تساوی رو 1 امتیاز و باخت رو 0 امتیاز در نظر گرفتیم !! چون اینطور که میگن سیستم امتیاز دهی تو بازی فوتبال اینجوریه !! :31: به هر حال کدساده شده ای که حدود 80 خط ازش کم شده و خوانایی اون افزایش پیدا کرده این هست :
زیاد مهم نیست که کاربر تو شروع برنامه کاراکتر وارد میکنه یا نه !!:13: چیزی که الان برام اهمیت داره قسمت انتهایی برنامه هست که مربوط به تحلیل تعداد گلها در شش تا 15 دقیقه بازی هست و اینکه محاسبه بشه که برای هر تیم چند درصد گلها تو کدام پانزده دقیقه به ثمر رسیده اند !! یعنی از خط قرمز به بعد !!:46:کد:#include <iostream.h>
void main()
{
char team[5][15];//used to enter the name of those five teams in this programm
int time[200]={0};
int counter[200]={0};//used to count the time of winnig and losing and saming the games
float cntphnd[200];//counter per one hundred that is used to descibe the percentage of scoring the goals in any minutes of the football match
int goal[5][5];
int mark[200];
int scored,recived,loseIndex,winIndex,sameIndex;
int i,j,k;
cout<<"Enter five teams"<<"\n";
for( i=0;i<5;i++)
for( i=0;i<5;i++)
cin>>team[i];
cout<<endl;
for( i=0;i<5;i++)
for( j=i;j<5;j++)
if(i!=j )
cout<<team[i]<<" "<<team[j]<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(i!=j){
cout<<"how many goals has "<<team[i]<<" scored to "<<team[j]<<"?";
cin>>goal[i][j];
}
cout<<"the chart of results is\n";
for(i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(i!=j)
cout<<team[i]<<" "<<goal[i][j]<<" **and** "<<team[j]<<" "<<goal[j][i]<<endl;
cout<<endl;
}
for( k=0;k<5; k++)//end of the first chart
{
cout << "FOR TEAM " << "*** " << team[ k ] <<" ***" << "\n";
scored = 0;
recived = 0;
winIndex = 3 * k + 1;
loseIndex = winIndex + 1;
sameIndex = loseIndex + 1;
for( int t = 0; t < 5; t++ )
{
if( goal[k][t] > goal[t][k] )
{
counter[winIndex]++;
}
else if( goal[k][t] < goal[t][k] )
{
counter[loseIndex]++;
}
else
{
counter[sameIndex]++;
}
if( k != t )
{
scored += goal[k][t];
recived += goal[t][k];
}
}
cout << "the number of scored goals" << " is " << scored << endl;
cout << "the number of recived goals" << "is " << recived << endl;
cout << "team " << team[k] << " won the football match " << counter[winIndex] << " times\n";
cout << "team " << team[k] << " lost the football match " << counter[loseIndex] << " times\n";
cout << "team " << team[k] << "got the same result for " << counter[sameIndex] - 1 << " times\n";
mark[k] = 3 * counter[winIndex] + counter[sameIndex] - 1;
cout << "the score of team " << team[k] << " is" << mark[k];//winning has 3 marks and saming has 1 mark and losing has 0 mark
cout << endl;
cout << endl;
cout << endl;
}
cout<<"enter times of scoring the goals of team "<<team[0];
for(i=0;i<(goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]);i++)
cin>>time[i];
for(i=0;i<(goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]);i++)
if(time[i]>90 || time[i]<0)
cout<<"error of entering the time";
else
{
for(i=0;i<(goal[4][0]+goal[4][1]+goal[4][2]+goal[4][3]);i++)
if(0<=time[i] && time[i] <=15)
counter[16]++;
cntphnd[1] = float( (counter[16]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[1]<<" percent of goals of team "<<team[0]<<" scored between 0 and 15 minutes ";
cout<<endl;
if(16<=time[i] && time[i] <=30)
counter[17]++;
cntphnd[2]= float ((counter[17]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[2]<<" percent of goals of team "<<team[0]<<" scored between 16 and 30 minutes";
cout<<endl;
if( 31<= time[i] && time[i] <=45)
counter[18]++;
cntphnd[3]= float (counter[18]*100.)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]);
cout<<cntphnd[3]<<" percent of goals of team "<<team[0]<<" scored between 31 and 45 minutes ";
cout<<endl;
if(46<=time[i] && time[i]<=60)
counter[19]++;
cntphnd[4]= float ((counter[19]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[4]<<" pecent of goals of team "<<team[0]<<" scored between 46 and 60 minues ";
cout<<endl;
if(61<=time[i] && time[i]<=75)
counter[20]++;
cntphnd[5]= float ((counter[20]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[5]<<" percent of goals of team "<<team[0]<< "scored between 61 and 75 minutes ";
cout<<endl;
if(76<=time[i] && time[i]<=90)
counter[21]++;
cntphnd[6]=float((counter[21]*100)/(goal[0][1]+goal[0][2]+goal[0][3]+goal[0][4]));
cout<<cntphnd[6]<< " percent of goals of team "<<team[0]<<" scored between 76 and 90 minutes ";
cout<<endl;
}
}
به بیان ساده تر با گرفتن تعداد گلهای هر تیم و گرفتن دقایق به ثمر رسیدن گلها که تعداد دقایق همون تعداد گلهاست (( مثلا اگه تیمی 2 تا گل بزنه یکی از آنها دقیقه 34 و دومی در دقیقه 49 به ثمر رسیده که تعداد دو دقیقه برابر تعداد گلهاست و باید تحلیل بشه چند درصد گلها از 0 تا 15 و چند درصد از 16 تا 30 و ... چند درصد از 76 تا 90 دقیقه بازی به ثمر رسیده اند و اینکار باید برای همه تیمها تکرار بشه))
که البته اینجا هم مستلزم استفاده از حلقه های for و استفاده همزمان از چند پارامتر هست منتها بنده کله ام دود کرد :27:از بس که زور زدم تا یه الگوریتم برای اینکار پیدا کنم و از کد نویسی بیهوده تو انتهای برنامه جلوگیری که کاری بجز عدم خوانا شدن برنامه انجام نمیده جلوگیری کنم !!
نگاه کن چی بود چی شد :19:
:46::46:
ایول
:46: