this is the coding of 4cups(paper fold game) game that we played in schoolings...

#include<stdio.h>
#include<conio.h>
void even();
void odd();
void cal1();
void cal2();
void job();
char z[]="one",y[]="two",x[]="three",w[]="four",v[]="five",u[]="six",t[]="seven",s[]="eight";

void main()
{
  char a[10],b[]="red",c[]="green",d[]="blue",e[]="yellow"; 
  clrscr();
  printf("enter your favourite color from given choice:\n");
  printf("red\nblue\ngreen\nyellow\n");
  scanf("%s",&a);
  if(strcmp(a,b)==0||strcmp(a,c)==0)
   {
      printf("good luck .you have entered %s let us see your career!\n",a);
      odd();
   }
 else if(strcmp(a,d)==0||strcmp(a,e)==0)
  {
   printf("good luck .you have entered %s let us see your career!\n",a);
   even();
  }
 else
   printf("invalid option!try again!!");
 getch();
}

void odd()
 {
   char a[10];
   int c;
   printf("your choice is 3,4,7,8.enter your favourite number in words\n");
   scanf("%s",&a);
   if(strcmp(a,x)==0||strcmp(a,w)==0||strcmp(a,t)==0||strcmp(a,s)==0)
     {
       if(strlen(a)%2!=0)
             cal1();
       else
             cal2();
     }
 }

void even()
 {
   char b[10];
   int c;
   printf("your choice is 1,2,5,6.enter your favourite number in words\n");
   scanf("%s",&b);
   if(strcmp(b,z)==0||strcmp(b,y)==0||strcmp(b,v)==0||strcmp(b,u)==0)
     {
      if(strlen(b)%2!=0)
             cal1();
      else
             cal2();
      }      
}

void cal1()
{
 int c;
 printf("your choice is 3,4,7,8.enter your favourite number \n");
 scanf("%d",&c);
 if(c==3||c==4||c==7||c==8)
      job(c);
 else
      printf("invalid option!try again!!");
}

void cal2()
 {
   int c;
   printf("your choice is 1,2,5,6.enter your favourite number \n");
   scanf("%d",&c);
   if(c==1||c==2||c==5||c==6)
       job(c);
   else
       printf("invalid option!try again!!");
 }

void job(c)
{
 printf("you will become "); 
 switch(c)
  {
    case 1:printf("doctor");break;
    case 2:printf("engineer");break;
    case 3:printf("teacher");break;
    case 4:printf("nurse");break;
    case 5:printf("lawyer");break;
    case 6:printf("judge");break;
    case 7:printf("actor");break;
    case 8:printf("CEO");break;
   }
}

i got the recquired output also.but plz check my code
the logic is as follows..
the string length of color selected is considered and checked for odd or even
the odd number opens 3,4,7,8 and even number opens 1,2,5,6.
the number is given in words as input..and again the string length is checked for odd or even.then again,the odd number opens 3,4,7,8 and even number opens 1,2,5,6.
based on input the profession is displayed ..
plz sent me your suggestions and defects on the code so that i can improve myself..

Recommended Answers

All 6 Replies

1. Remove the dependency on conio.h
2. void main should be int main
3. No need for getch()/ clrscr
4. Get rid of scanf

Are you using Turbo - C ?

Turbo C is really outdated maybe you want to consider switching to a newer editor

tell me some new editors and also tell me some reliable websites to download it..

Maybe you google for them .....
Its not that hard

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.