IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Closed TopicStart new topic

How to make 9 8 7 6 =24


LuciferStar
no avatar
Advanced Member
*******
Group: Members
Posts: 114
Joined: 9-August 04
From: Suzhou Jiangsu China
Member No.: 743



Post #1 post Aug 10 2004, 07:44 AM
CODE
#include "stdio.h"[br]#include "process.h"[/br]int fun0(int x,int y){return (x+y);}[br]int fun1(int x,int y){return (x-y);}[/br]int fun2(int x,int y){return (x*y);}[br]int fun3(int x,int y){return (x/y);}[/br]int (*assign[4])(int x,int y);[br]void assign_function(void)[/br]{[br]assign[0]=fun0;[/br]assign[1]=fun1;[br]assign[2]=fun2;[/br]assign[3]=fun3;[br]}[/br]//const int data[4]={9,8,7,1};[br]int data[4]={9,8,7,1};[/br]const int fetch[24][4]={[br]{3,2,1,0},{0,3,2,1},{1,0,3,2},{2,1,0,3},[/br]{3,1,2,0},{0,3,1,2},{2,0,3,1},{1,2,0,3},[br]{3,0,1,2},{2,3,0,1},{1,2,3,0},{0,1,2,3},[/br]{3,2,0,1},{1,3,2,0},{0,1,3,2},{2,0,1,3},[br]{3,0,1,2},{1,3,0,2},{2,1,3,0},{0,2,1,3},[/br]{3,1,0,2},{2,3,1,0},{0,2,3,1},{1,0,2,3}};[br]int calculator[4];[/br]void result(int x,int y,int r,int n)[br]{[/br]int a[4],b[4];[br]char  fomular[20],o[4]={'+','-','*','/'};[/br]for(int i=0;i<4;i++)[br]{[/br]a[i]=fetch[x][i];[br]b[i]=data[fetch[y][i]];//printf("a[%d]:%d  b[%d]:%d  o[%d]:%c  o[a[%d]]:%c\n",i,a[i],i,b[i],i,o[i],i,o[a[i]]);[br]}[/br]if((a[0]==0||a[0]==1)&&(a[1]==2||a[1]==3))[/br]   sprintf(fomular,"Method %d:  (%d%c%d)%c%d%c%d=%d\n",n,b[0],o[a[0]],b[1],o[a[1]],b[2],o[a[2]],b[3],r);[br]else if((a[0]==2||a[0]==3)&&(a[3]!=2||a[3]!=3))[/br]   sprintf(fomular,"Method %d:  %d%c%d%c%d%c%d=%d\n",n,b[0],o[a[0]],b[1],o[a[1]],b[2],o[a[2]],b[3],r);[br]else sprintf(fomular,"Method %d:  (%d%c%d%c%d)%c%d=%d\n",n,b[0],o[a[0]],b[1],o[a[1]],b[2],o[a[2]],b[3],r);[/br]//printf("\tResult:\n");[br]printf("\t%s",fomular);[/br][br]}[/br][br]void main(void)[/br]{  int r=24;[br]   //int temp;[/br]   int n=0;[br]assign_function();[/br]printf("\t\tAchieve 24 point\n\n\tBy Lucifer Star\n\tSingle Studio\n\t\tEMAIL:LetMeGetOne@hotmail.com\n\n");[br]printf("*****************************************\n");[/br]printf("\tPlease input 1st number:");[br]scanf("%d",&data[0]);[/br]printf("\tPlease input 2nd number:");[br]scanf("%d",&data[1]);[/br]printf("\tPlease input 3rd number:");[br]scanf("%d",&data[2]);[/br]printf("\tPlease input 4th number:");[br]scanf("%d",&data[3]);[/br]printf("\tWhat do you want to achieve(default:24):");[br]scanf("%d",&r);[/br]//scanf("%d",&temp);[br]//temp=getch();[/br]//if(temp!=0x0d) r=temp;[br][/br]printf("\n     ***********************************\n");[br]if(data[0]==0||data[1]==0||data[2]==0||data[3]==0) {printf("The 4 numbers shouldn't be 0!");exit(0);}[/br]for(int ii=0;ii<24;ii++)[br]{[/br]   for(int i=0;i<24;i++)[br]   {[/br]    int z=0;[br]    for(int j=0;j<4;j++)[/br]    {[br]  calculator[j]=data[fetch[i][j]];[/br]    }[br]    for(int k=0;k<3;k++)[/br]    {[br]  if(k==0)[/br]  {[br]     if(calculator[0]%calculator[1]!=0&&fetch[ii][0]==3)[/br]        {z=0;break;}[br]     else z=assign[fetch[ii][k]](calculator[k],calculator[k+1]);[/br]  }[br]  else[/br]  {  if(fetch[ii][k]==3)[br]       if(calculator[k+1]==0||z==0||(z%calculator[k+1])!=0)[/br]      {z=0;break;}[br]     z=assign[fetch[ii][k]](z,calculator[k+1]);[/br]  }[br]    }[/br]    if(z==r)[br]    {    n++;result(ii,i,r,n);   }[/br]    }[br]}[/br]printf("\n******************************************\n");[br]if(n==0) printf("Sorry,it's unable to do so!");[/br]else printf("Thanks for using my software!");
}
Go to the top of the page
+Quote Post
neeki4444
no avatar
Newbie [Level 2]
**
Group: Members
Posts: 38
Joined: 31-August 04
Member No.: 967



Post #2 post Sep 1 2004, 02:18 PM
don't use printf use cout its more secure. Using print may lead to bufferover flows and hackers can easily gain control of the computer by injecting some extra code themselves
Go to the top of the page
+Quote Post
OpaQue
no avatar
Administrator
**************
Group: Admin
Posts: 1,625
Joined: 11-June 04
From: Somewhere in Time & Space.
Member No.: 1
myCENT:NEGATIVE[-78.06]



Post #3 post Sep 1 2004, 06:07 PM
I prefer printf because it is fast and gives more power. Formatting can be done easily. Besides, looking at the above program, since iostream.h is not included, cout cannot be included. its a pure c program.
Go to the top of the page
+Quote Post
LuciferStar
no avatar
Advanced Member
*******
Group: Members
Posts: 114
Joined: 9-August 04
From: Suzhou Jiangsu China
Member No.: 743



Post #4 post Sep 3 2004, 11:40 AM
I've learned C for more than 5 years,
and I found it's hard for me to learn C++,though I can understand it.

CLASS is hard to me.

the output of cout is variable,uncontrolable,I think.
Go to the top of the page
+Quote Post
goranche
no avatar
Newbie
*
Group: Members
Posts: 7
Joined: 24-September 04
Member No.: 1,253



Post #5 post Sep 24 2004, 01:53 PM
don't be scared with c++. Every thing that you are doing in C++ you CAN do in C but in more complex way...
classes are invented to make peoples unsecured but it's not so hard...

To all of you...
I'm from Serbia. I'm new here on Trap17. I'm pleased to be with you folks, but you must forgive me on my "bad" english.. wink.gif
Go to the top of the page
+Quote Post
buxgoddess
no avatar
Super Member
*********
Group: Members
Posts: 285
Joined: 2-November 08
From: Cosmos
Member No.: 71,240
myCENT:42.91



Post #6 post Dec 25 2008, 09:04 AM
Now something I get to add here is the way the quoted text is posted. There are [br] tags in between the lines. You cannot directly copy the text into the c++ ide and you need to edit them. I would suggest that any such thing copied from another location must be edited so that they look organized. Look at the first quoted text, they just look junk and as a first time learner will find the codes are not very friendly. Any matter must be organized as I think the posts are done for some information and not wasting time over what is quoted and find that there are too many errors or logical problems with the program. All people who post their posts must be held responsible and asked to edit their posts for making them more informative and neat. Incentives may be given. And for badly posted posts there should be no myCent awarded until resolved by editing. I would not like too much mods/admin intervention but a neater look is definitely welcome.
Go to the top of the page
+Quote Post
akira550
no avatar
Super Member
*********
Group: Members
Posts: 259
Joined: 19-September 09
From: Geek Ville
Member No.: 88,395
myCENT:75.80



Post #7 post Sep 19 2009, 08:57 AM
you can't use the cout function because the iostream.h is not included the program
hmm anyway cout is more secure than printf but if its only a school project just use printf happy.gif
Go to the top of the page
+Quote Post

Closed TopicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No new   16 -gladiator_us- 21,937 24th August 2009 - 11:05 AM
Last post by: jamjamnorman
No New Posts   7 SilverBoarder 14,288 9th February 2009 - 11:02 AM
Last post by: aloKNsh
No New Posts   9 shadowx 3,328 12th October 2009 - 07:12 PM
Last post by: manish-mohania
No new   14 Raptrex 17,539 8th December 2008 - 01:40 PM
Last post by: carToon
No New Posts 7 arash 10,444 16th May 2009 - 04:13 AM
Last post by: k_nitin_r
No New Posts   6 Lunaray 9,440 10th September 2004 - 08:43 AM
Last post by: Lunaray
No New Posts   8 sofiaweb 558 31st August 2009 - 06:09 AM
Last post by: shova
No New Posts   3 Triple X 9,609 18th December 2008 - 10:52 PM
Last post by: minimcmonkey
No New Posts   4 electriic ink 1,773 25th July 2006 - 07:28 PM
Last post by: electriic ink
No new   14 Shadow 16,380 2nd April 2009 - 07:06 AM
Last post by: jesseruu
No new   25 nicky1 21,971 31st October 2009 - 01:14 PM
Last post by: TheDarkHacker
No new   45 GamerGlitch 8,567 28th October 2009 - 09:48 AM
Last post by: aloKNsh
No New Posts 5 odomike 5,060 4th August 2009 - 01:30 AM
Last post by: The Simpleton
No New Posts   2 Ungreezor 781 9th November 2009 - 08:31 PM
Last post by: iG-KruScape
No New Posts   0 Lyon 2,645 3rd November 2004 - 07:22 PM
Last post by: Lyon


 



RSS Open Discussion Time is now: 22nd November 2009 - 12:22 AM

Web Hosting Powered by ComputingHost.com.