Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<8051.h>
  3. #include <stdlib.h>
  4. char getchar();
  5. void putchar(char c);
  6. unsigned char delay();
  7.  
  8. void main()
  9. {
  10.    
  11.     int x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,q,p,count,end,score,questions;
  12.     h=1;
  13.     i=0;
  14.     j=3;
  15.     k=7;
  16.     l=4;
  17.     count=0;
  18.     score=0;
  19.     questions=0;
  20.  
  21.    
  22.     printf("#WELCOME TO THE MATHS GAME!#\n");
  23.  
  24.     printf("#WHERE YOUR MATHS KNOWLEDGE IS TESTED!#\n");
  25.  
  26.     printf("INFO:YOU HAVE 'THREE' LIVE LINES!\n");
  27.  
  28.     printf("INFO:GET THREE WRONG AND ITS GAMEOVER!!\n");
  29.  
  30.     printf("TRUE=1, FALSE=0\n");
  31.  
  32.     printf("Is 5>4 ?\n");
  33.     questions=questions+1;
  34.     x=getchar();
  35.     if (x==h)
  36.         {
  37.         printf("CORRECT!\n");
  38.     score=score+1;
  39.     }
  40.             else if (x==i)
  41.             {
  42.             printf("WRONG!\n");
  43.         count=count+1;
  44.             }
  45.                 else if(x>1)
  46.  {
  47.                     printf("Is 5>4 ?\n");
  48.                     printf("True=1!, False=0!\n");
  49.                     x=getchar();
  50.             if (x==h)
  51.                 {
  52.                 printf("CORRECT!\n");
  53.             score=score+1;
  54.             }
  55.                     else if (x==i)
  56.                     {
  57.                     printf("WRONG!\n");
  58.                 count=count+1;
  59.                     }
  60. }
  61.                 if (count<3)
  62.                             {
  63.                         printf("Is 2x3=6\n");
  64.                     questions=questions+1;
  65.                     y=getchar();
  66.                     if (y==h)
  67.                         {
  68.                             printf("CORRECT!\n");
  69.                     score=score+1;
  70.                     }
  71.                         else if (y==i)
  72.                             {
  73.                             printf("WRONG!\n");
  74.                         count=count+1;
  75.                             }
  76.                                 else if(y>1)
  77.                                 {
  78.                                     printf("Is 2x3=6\n");
  79.                                     printf("True=1!, False=0!\n");
  80.                                     y=getchar();
  81.                             if (y==h)
  82.                                 {
  83.                                     printf("CORRECT!\n");
  84.                             score=score+1;
  85.                             }
  86.                                 else if (y==i)
  87.                                     {
  88.                                     printf("WRONG!\n");
  89.                                 count=count+1;
  90.                                     }
  91.                                     }
  92.                                 }
  93.                                         if (count<3)
  94.                             {
  95.                         printf("How many sides does a heptagon have?\n");
  96.                     printf("A=3....B=4....C=7\n");
  97.                     questions=questions+1;
  98.                     n=getchar();
  99.                     if (n==k)
  100.                         {
  101.                             printf("CORRECT!\n");
  102.                     score=score+1;
  103.                     }
  104.                         else if (n==h)
  105.                             {
  106.                             printf("WRONG!\n");
  107.                         count=count+1;
  108.                             }
  109.                             else if (n==l)
  110.                             {
  111.                             printf("WRONG!\n");
  112.                         count=count+1;
  113.                             }
  114.                                 else if((n!=3)&&(n!=4))
  115.                                 {
  116.                             printf("Number outside of range!!!!!\n");
  117.                                     printf("How many sides does a heptagon have?\n");
  118.                             printf("A=3....B=4....C=7\n");
  119.                             questions=questions+1;
  120.                                 n=getchar();
  121.                                 if (n==k)
  122.                                     {
  123.                                         printf("CORRECT!\n");
  124.                                 score=score+1;
  125.                                 }
  126.                                     else if (n==h)
  127.                                         {
  128.                                         printf("WRONG!\n");
  129.                                     count=count+1;
  130.                                         }
  131.                                         else if (n==l)
  132.                                             {
  133.                                             printf("WRONG!\n");
  134.                                         count=count+1;
  135.                                             }
  136.                                             else if(n!=7)
  137.                                                 {
  138.                                             printf("Number outside of range!!!!!\n");
  139.                                                     printf("How many sides does a heptagon have?\n");
  140.                                             printf("A=3....B=4....C=7\n");
  141.                                             questions=questions+1;
  142.                                             n=getchar();
  143.                                             if (n==k)
  144.                                                 {
  145.                                                     printf("CORRECT!\n");
  146.                                             score=score+1;
  147.                                             }
  148.                                                 else if (n==h)
  149.                                                     {
  150.                                                     printf("WRONG!\n");
  151.                                                 count=count+1;
  152.                                                     }
  153.                                                 else if (n==l)
  154.                                                     {
  155.                                                     printf("WRONG!\n");
  156.                                                 count=count+1;
  157.                                                     }
  158.                             }  
  159.                                 if (count<3)
  160.                                             {
  161.                                 printf("Is 1+1=2\n");
  162.                                 questions=questions+1;
  163.                                         z=getchar();
  164.                                         if (z==h)
  165.                                         {
  166.                                         printf("CORRECT!\n");
  167.                                 score=score+1;
  168.                                     }
  169.                                         else if (z==i)
  170.                                         {
  171.                                         printf("WRONG!\n");
  172.                                     count=count+1;
  173.                                         }
  174.                                             else if(z>1)
  175.                                             {
  176.                                                 printf("Is 1+1=2\n");
  177.                                                 printf("True=1!, False=0!\n");
  178.                                                 z=getchar();
  179.                                         if (z==h)
  180.                                                 {
  181.                                                 printf("CORRECT!\n");
  182.                                         score=score+1;
  183.                                             }
  184.                                                 else if (z==i)
  185.                                                 {
  186.                                                 printf("WRONG!\n");
  187.                                             count=count+1;
  188.                                                 }
  189.                                             }
  190.                                             if (count<3)
  191.                                                         {
  192.                                                     printf("Is 1+4=7\n");
  193.                                             questions=questions+1;
  194.                                                     a=getchar();
  195.                                                     if (a==h)
  196.                                                     {
  197.                                                         printf("WRONG!\n");
  198.                                             count=count+1;
  199.                                             }
  200.                                                 else if (a==i)
  201.                                                     {
  202.                                                     printf("CORRECT!\n");
  203.                                                 score=score+1;
  204.                                                     }
  205.                                                         else if(a>1)
  206.                                                         {
  207.                                                             printf("Is 1+4=7\n");
  208.                                                             printf("True=1!, False=0!\n");
  209.                                                             a=getchar();
  210.                                                     if (a==h)
  211.                                                             {
  212.                                                                 printf("WRONG!\n");
  213.                                                     count=count+1;
  214.                                                     }
  215.                                                         else if (a==i)
  216.                                                             {
  217.                                                             printf("CORRECT!\n");
  218.                                                         score=score+1;
  219.                                                             }
  220.                                                         }
  221.                                                         if (count<3)
  222.                                                                     {
  223.                                                                     printf("Is 3-2=10\n");
  224.                                                         questions=questions+1;
  225.                                                                     b=getchar();
  226.                                                                     if (b==h)
  227.                                                                     {
  228.                                                                     printf("WRONG!\n");
  229.                                                         count=count+1;
  230.                                                             }
  231.                                                             else if (b==i)
  232.                                                                 {
  233.                                                                 printf("CORRECT!\n");
  234.                                                             score=score+1;
  235.                                                                 }
  236.                                                                     else if(b>1)
  237.                                                                     {
  238.                                                                         printf("Is 3-2=10\n");
  239.                                                                 printf("True=1!, False=0!\n");
  240.                                                                         b=getchar();
  241.                                                                 if (b==h)
  242.                                                                             {
  243.                                                                             printf("WRONG!\n");
  244.                                                                 count=count+1;
  245.                                                                     }
  246.                                                                     else if (b==i)
  247.                                                                         {
  248.                                                                         printf("CORRECT!\n");
  249.                                                                     score=score+1;
  250.                                                                         }
  251.                                                                     }
  252.                                                                     if (count<3)
  253.                                                                                 {
  254.                                                                                 printf("Is 64^(1/2)=8\n");
  255.                                                                     questions=questions+1;
  256.                                                                                 c=getchar();
  257.                                                                                 if (c==h)
  258.                                                                                 {
  259.                                                                                     printf("CORRECT!\n");
  260.                                                                     score=score+1;
  261.                                                                     }
  262.                                                                         else if (c==i)
  263.                                                                             {
  264.                                                                             printf("WRONG!\n");
  265.                                                                         count=count+1;
  266.                                                                             }
  267.                                                                                 else if(c>1)
  268.                                                                                 {
  269.                                                                                     printf("Is 64^(1/2)=8\n");
  270.                                                                                     printf("True=1!, False=0!\n");
  271.                                                                                     c=getchar();
  272.                                                                             if (c==h)
  273.                                                                                         {
  274.                                                                                             printf("CORRECT!\n");
  275.                                                                             score=score+1;
  276.                                                                             }
  277.                                                                                 else if (c==i)
  278.                                                                                     {
  279.                                                                                     printf("WRONG!\n");
  280.                                                                                 count=count+1;
  281.                                                                                     }
  282.                                                                                 }
  283.                                                                                                 if (count<3)
  284.                             {
  285.                         printf("How many sides does a triangle have?\n");
  286.                     printf("A=3....B=1....C=7\n");
  287.                     questions=questions+1;
  288.                     m=getchar();
  289.                     if (m==j)
  290.                         {
  291.                             printf("CORRECT!\n");
  292.                     score=score+1;
  293.                     }
  294.                         else if (m==h)
  295.                             {
  296.                             printf("WRONG!\n");
  297.                         count=count+1;
  298.                             }
  299.                             else if (m==k)
  300.                             {
  301.                             printf("WRONG!\n");
  302.                         count=count+1;
  303.                             }
  304.                                 else if((m!=3)&&(m!=1))
  305.                                 {
  306.                             printf("Number outside of range!!!!!\n");
  307.                                     printf("How many sides does a triangle have?\n");
  308.                             printf("A=3....B=1....C=7\n");
  309.                                     m=getchar();
  310.                             if (m==j)
  311.                                 {
  312.                                     printf("CORRECT!\n");
  313.                             score=score+1;
  314.                             }
  315.                                 else if (m==h)
  316.                                     {
  317.                                     printf("WRONG!\n");
  318.                                 count=count+1;
  319.                                     }
  320.                                     else if (m==k)
  321.                                         {
  322.                                         printf("WRONG!\n");
  323.                                     count=count+1;
  324.                                         }
  325.                             else if(m!=7)
  326.                                 {
  327.                             printf("Number outside of range!!!!!\n");
  328.                                     printf("How many sides does a triangle have?\n");
  329.                             printf("A=3....B=1....C=7\n");
  330.                                     m=getchar();
  331.                             if (m==j)
  332.                                 {
  333.                                     printf("CORRECT!\n");
  334.                             score=score+1;
  335.                             }
  336.                                 else if (m==h)
  337.                                     {
  338.                                     printf("WRONG!\n");
  339.                                 count=count+1;
  340.                                     }
  341.                                     else if (m==k)
  342.                                         {
  343.                                         printf("WRONG!\n");
  344.                                     count=count+1;
  345.                                         }
  346.                             }
  347.                                                                                 if (count<3)
  348.                                                                                             {
  349.                                                                                                 printf("Is 4/6=2/3\n");
  350.                                                                                 questions=questions+1;
  351.                                                                                                 d=getchar();
  352.                                                                                                 if (d==h)
  353.                                                                                                 {
  354.                                                                                                 printf("CORRECT!\n");
  355.                                                                                 score=score+1;
  356.                                                                                     }
  357.                                                                                     else if (d==i)
  358.                                                                                             {
  359.                                                                                             printf("WRONG!\n");
  360.                                                                                         count=count+1;
  361.                                                                                             }
  362.                                                                                             else if(d>1)
  363.                                                                                                 {
  364.                                                                                                 printf("Is 4/6 = 2/3?\n");
  365.                                                                                                     printf("True=1!, False=0!\n");
  366.                                                                                                     d=getchar();
  367.                                                                                             if (d==h)
  368.                                                                                                             {
  369.                                                                                                             printf("CORRECT!\n");
  370.                                                                                             score=score+1;
  371.                                                                                                 }
  372.                                                                                                 else if (d==i)
  373.                                                                                                     {
  374.                                                                                                     printf("WRONG!\n");
  375.                                                                                                 count=count+1;
  376.                                                                                                     }
  377.                                                                                                             if (count<3)
  378.                             {
  379.                         printf("How many sides does a square have?\n");
  380.                     printf("A=3....B=4....C=7\n");
  381.                     questions=questions+1;
  382.                     o=getchar();
  383.                     if (o==l)
  384.                         {
  385.                             printf("CORRECT!\n");
  386.                     score=score+1;
  387.                     }
  388.                         else if (o==k)
  389.                             {
  390.                             printf("WRONG!\n");
  391.                         count=count+1;
  392.                             }
  393.                             else if (o==j)
  394.                                 {
  395.                                 printf("WRONG!\n");
  396.                             count=count+1;
  397.                                 }
  398.                                     else if((o!=3)&&(o!=4))
  399.                                     {
  400.                                 printf("Number outside of range!!!!!\n");
  401.                                         printf("How many sides does a square have?\n");
  402.                                 printf("A=3....B=4....C=7\n");
  403.                                 questions=questions+1;
  404.                                 o=getchar();
  405.                                 if (o==l)
  406.                                     {
  407.                                         printf("CORRECT!\n");
  408.                                 score=score+1;
  409.                                 }
  410.                                     else if (o==k)
  411.                                         {
  412.                                         printf("WRONG!\n");
  413.                                     count=count+1;
  414.                                         }
  415.                                         else if (o==j)
  416.                                             {
  417.                                             printf("WRONG!\n");
  418.                                         count=count+1;
  419.                                             }
  420.                                             else if(o!=7)
  421.                                                 {
  422.                                             printf("Number outside of range!!!!!\n");
  423.                                                     printf("How many sides does a square have?\n");
  424.                                             printf("A=3....B=4....C=7\n");
  425.                                             questions=questions+1;
  426.                                             n=getchar();
  427.                                             if (o==l)
  428.                                                 {
  429.                                                     printf("CORRECT!\n");
  430.                                             score=score+1;
  431.                                             }
  432.                                                 else if (o==k)
  433.                                                     {
  434.                                                     printf("WRONG!\n");
  435.                                                 count=count+1;
  436.                                                     }
  437.                                                     else if (o==j)
  438.                                                         {
  439.                                                         printf("WRONG!\n");
  440.                                                     count=count+1;
  441.                                                         }
  442.                             }  
  443.                                                                                                 }
  444.                                                                                                 if (count<3)
  445.                                                                                                             {
  446.                                                                                                                 printf("Is 7>9\n");
  447.                                                                                                 questions=questions+1;
  448.                                                                                                                 e=getchar();
  449.                                                                                                                 if (e==h)
  450.                                                                                                                 {
  451.                                                                                                                 printf("WRONG!\n");
  452.  
  453.                                                                                                 count=count+1;
  454.                                                                                                 }
  455.                                                                                                     else if (e==i)
  456.                                                                                                         {
  457.                                                                                                         printf("CORRECT!\n");
  458.                                                                                                     score=score+1;
  459.                                                                                                         }
  460.                                                                                                             else if(e>1)
  461.                                                                                                             {
  462.                                                                                                                 printf("Is 7>9\n");
  463.                                                                                                                 printf("True=1!, False=0!\n");
  464.                                                                                                                 e=getchar();
  465.                                                                                                         if (e==h)
  466.                                                                                                                         {
  467.                                                                                                                         printf("WRONG!\n");
  468.                                                                                                         count=count+1;
  469.                                                                                                         }
  470.                                                                                                             else if (e==i)
  471.                                                                                                                 {
  472.                                                                                                                 printf("CORRECT!\n");
  473.                                                                                                             score=score+1;
  474.                                                                                                                 }
  475.                                                                                                             }
  476.                                                                                                             if (count<3)
  477.                                                                                                                         {
  478.                                                                                                                                 printf("Is 5-3=23\n");
  479.                                                                                                             questions=questions+1;
  480.                                                                                                                                 f=getchar();
  481.                                                                                                                                 if (f==h)
  482.                                                                                                                                 {
  483.                                                                                                                                 printf("WRONG!\n");        
  484.                                                                                                             count=count+1;
  485.                                                                                                                 }
  486.                                                                                                                 else if (f==i)
  487.                                                                                                                     {
  488.                                                                                                                     printf("CORRECT!\n");
  489.                                                                                                                 score=score+1;
  490.                                                                                                                     }
  491.                                                                                                                         else if(f>1)
  492.                                                                                                                         {
  493.                                                                                                                             printf("Is 5-3=23\n");
  494.                                                                                                                             printf("True=1!, False=0!\n");
  495.                                                                                                                             f=getchar();
  496.                                                                                                                     if (f==h)
  497.                                                                                                                                         {
  498.                                                                                                                                         printf("WRONG!\n");
  499.                                                                                                                     count=count+1;
  500.                                                                                                                         }
  501.                                                                                                                         else if (f==i)
  502.                                                                                                                             {
  503.                                                                                                                             printf("CORRECT!\n");
  504.                                                                                                                         score=score+1;
  505.                                                                                                                             }
  506.                                                                                                                         }
  507.                                                                                                                         if (count<3)
  508.                                                                                                                                     {
  509.                                                                                                                                             printf("Is 4x5=0\n");
  510.                                                                                                                         questions=questions+1;
  511.                                                                                                                                             g=getchar();
  512.                                                                                                                                             if (g==h)
  513.                                                                                                                                             {
  514.                                                                                                                                                 printf("WRONG!\n");
  515.                                                                                                                         count=count+1;
  516.                                                                                                                                             }
  517.                                                                                                                             else if (g==i)
  518.                                                                                                                                 {
  519.                                                                                                                                 printf("CORRECT!\n");
  520.                                                                                                                             score=score+1;
  521.                                                                                                                             end=1;
  522.                                                                                                                                 }
  523.                                                                                                                                     else if(g>1)
  524.                                                                                                                                     {
  525.                                                                                                                                         printf("Is 4x5=0\n");
  526.                                                                                                                                         printf("True=1!, False=0!\n");
  527.                                                                                                                                         g=getchar();
  528.                                                                                                                                 if (g==h)
  529.                                                                                                                                                     {
  530.                                                                                                                                                         printf("WRONG!\n");
  531.                                                                                                                                 count=count+1;
  532.                                                                                                                                                     }
  533.                                                                                                                                     else if (g==i)
  534.                                                                                                                                         {
  535.                                                                                                                                         printf("CORRECT!\n");
  536.                                                                                                                                     score=score+1;
  537.                                                                                                                                     end=1;
  538.                                                                                                                                         }
  539.                                                                                                                                     }
  540.                                                                                                                                     }
  541.                                                                                                                             }
  542.                                                                                                                         }
  543.                                                                                                                     }
  544.                                                                                                                 }
  545.                                                                                                             }
  546.                                                                                                         }
  547.                                                                                                     }
  548.                                                                                                
  549.  
  550.  
  551.  
  552.  
  553.  
  554. /*unsigned char delay(void)
  555. {
  556.     unsigned char q=0xFF;
  557.     while(q)
  558.     q--;
  559. }*/
  560.  
  561. if ((g==i)&&(end=1))
  562.                 {
  563.                     printf("congratulations you have completed the game!\n");
  564.             printf("And your total score is....%d",score);
  565.             printf("out of %d\n",questions);
  566.                 }
  567.            
  568.         else if(count>2)
  569.                 {
  570.                     printf("###########GAME OVER#########\n");
  571.             printf("And your total score is....%d",score);
  572.             printf("out of %d\n",questions);
  573.                     getchar();
  574. }
  575. }
  576. }
  577. }
  578.  
  579.  
  580.  
  581. void putchar(char c)                //write character to lcd or serial port
  582. }
  583.         while(!TI);  /* wait for ready */
  584.         TI=0;
  585.         SBUF = c;
  586.  
  587. }
  588.  
  589. char getchar()              // get character from serial port
  590. {
  591.     char c;
  592.     while(!RI);
  593.     RI =0;
  594.     c = SBUF;
  595.     return (c);
  596. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement