Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,248 Programmers. There are 2,192 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

How do I make an easy calculator? In Miracle c

 
Reply to this topicStart new topic

How do I make an easy calculator? In Miracle c, Help?

rmexstud
post 5 Apr, 2008 - 12:53 PM
Post #1


New D.I.C Head

*
Joined: 5 Apr, 2008
Posts: 1



CODE

strcat(goal,gtop);
strcat(goal,gmid);
strcat(goal,gbot);

for (line=0; line <300; line++)
     {   action[line][0] = 0;
         opena  [line][0] = 0;   }

strcpy(opena[0],initial);

for(;;)
{
strcpy(current,opena[0]);
strcpy(closed[close_num++],current);
if (strcmp(goal,current) == 0)
     { printf("Solution found : %s \n",action[0]);
       exit(0); }

strcpy(store,current);
s_pos = -1;

for(s_loop=0; s_loop<10; s_loop++)
{ if(*(current+s_loop) == '.') s_pos = s_loop; }

if (s_pos == -1)
     { printf("Illegal input.");
       exit(0); }

/* Configuration where empty square goes UP. */

if (s_pos > 2) {

current[s_pos] = current[s_pos - 3];
*(current + s_pos - 3) = '.';
got_flag = 0;

for (closed_check=0; closed_check<=close_num; closed_check++)
{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }

if (got_flag == 0) { strcpy(opena[++open_num],current);
                     strcpy(action[open_num],action[0]);
                     strcat(action[open_num],"U"); } }

/* Configuration where empty square goes DOWN. */

strcpy(current,store);

if (s_pos < 6) {

current[s_pos] = current[s_pos+3];
*(current + s_pos + 3) = '.';
got_flag = 0;

for (closed_check=0; closed_check<=close_num; closed_check++)
{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }

if(got_flag == 0) { strcpy(opena[++open_num],current);
                    strcpy(action[open_num],action[0]);
                    strcat(action[open_num],"D"); } }

/* Configuration where empty square goes LEFT. */

strcpy(current,store);

if((s_pos!=0) && (s_pos!=3) && (s_pos!=6)) {

current[s_pos] = current[s_pos-1];
*(current + s_pos - 1) = '.';
got_flag = 0;

for (closed_check=0; closed_check<=close_num; closed_check++)
{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }

if(got_flag==0) { strcpy(opena[++open_num],current);
                  strcpy(action[open_num],action[0]);
                  strcat(action[open_num],"L"); } }

/* Configuration where empty square goes RIGHT. */

strcpy(current,store);

if((s_pos!=2) && (s_pos!=5) && (s_pos!=8)) {
current[s_pos] = current[s_pos+1];
*(current + s_pos + 1) = '.';
got_flag=0;

for(closed_check=0; closed_check<=close_num; closed_check++)
{ if(strcmp(current,closed[closed_check]) == 0) got_flag=1; }

if(got_flag == 0) { strcpy(opena[++open_num],current);
                    strcpy(action[open_num],action[0]);
                    strcat(action[open_num],"R"); } }

for(shift=0; shift<open_num; shift++)
{ strcpy(opena[shift], opena[shift+1]);
  strcpy(action[shift],action[shift+1]); } } }


This post has been edited by PsychoCoder: 5 Apr, 2008 - 01:43 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


PsychoCoder
post 5 Apr, 2008 - 01:42 PM
Post #2


ToCode || !ToCode

Group Icon
Joined: 26 Jul, 2007
Posts: 5,857

Moved to the Other Languages Forum smile.gif

This post has been edited by PsychoCoder: 5 Apr, 2008 - 01:43 PM
User is online!Profile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 08:49AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month