ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

كممممممممممممممممك جعبه جادويي

 
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming
View previous topic :: View next topic  
Author Message
parnian
دوست آشناي سايت


Joined: 29 Jul 2006
Posts: 72

PostPosted: Tue Feb 27, 2007 12:51 pm    Post subject: كممممممممممممممممك جعبه جادويي Reply with quote

با سلام
برنامه اي مي خواستم كه مسابقه در صد ثانيه را انجام دهد به زبان c (كه به اينصورت مي باشد كه اين بازي بين دو نفر مي باشد كه يك نفر يك عدد مثلا 5 رقمي را انتخاب ميكند (به طور تصادفي و دلخواه ) و بدون آنكه به طرف مقابل بگويد و طرف مقابل شروع به گفتن تك تك ارقام مي گويد تا 5 رقم و بعد نفر اول به آن رقم هاي درست را با رنگ سبز و رقم هاي نادرست را كه اصلا جزء ارقام نيستند را با رنگ قرمز و آن رقم هايي را كه جزء آن 5 رقم هستند ولي جاي آْن درست نيست را بارنگ زرد جايگزين مي كند تا هنگاميكه نفر دوم بتواند حدس بزند
با تشكر
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Tue Feb 27, 2007 8:08 pm    Post subject: Reply with quote

اگه برنامه رو كامل و "آ"ماده مي خواي . بايد توي بخش پذيرش پروژه بنويسي . اينجا جاي رفع اشكاله .

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int aryA[5],aryRnd[5],aryClr[5]={0};
void make_random();
void show_random();
void make_color();
int show_color();
void  main()
{
  int found=0,a=0,i;
  clrscr();
  make_random();
  while( (!found) && (a<5) )
  {
     printf("\n\n %d) please enter 5 number between 0-9 \n\n",a+1);
     for(i=0;i<5;i++)
      {
         scanf("%d",&aryA[i]) ;
         if( (aryA[i]>9) || (aryA[i]<0) ) aryA[i]=0;
      }
     make_color();
     found=show_color();
     a+=1;
  }
  show_random();
  getch();
}
void make_random()
{
   int i=0;
   randomize();
   for (i=0;i<5;i++)
         aryRnd[i]=random (10);
}
void show_random()
{
   int i=0;
   textcolor(GREEN);
   printf("\n\n\n\n The Correct Number is :");
   for (i=0;i<5;i++)
        cprintf(" %d ", aryRnd[i]);
}
void make_color()
{
  int i,j;
  for (i=0;i<5;i++)aryClr[i]=0;
  for (i=0;i<5;i++)
      if(aryA[i]==aryRnd[i])
       aryClr[i]=2;
  for (i=0;i<5;i++)
   for(j=0;j<5;j++)
       if( (aryA[i]==aryRnd[j]) && (aryClr[i]!=2) )
       aryClr[i]=1;

}
int show_color()
{
   int i;
   for(i=0;i<5;i++)
      {
   if (aryClr[i]==0)
      textcolor(RED);
   else if(aryClr[i]==1)
      textcolor(YELLOW);
   else
      textcolor(GREEN);
   cprintf(" %d",aryA[i]);
      }
   for(i=0;i<5;i++)
   if(aryClr[i]!=2)
      return 0;
   return 1;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum