converting strokes from c++ to c!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • queen rossie

    converting strokes from c++ to c!

    hi,

    i have a problem to change this C++ code language to C language...



    Code:
    #include <iostream>
    #include <conio.h>
    
    void choosePlay(char);
    void playGame(int,int,int,int);
    void match(int[][4]);
    int r1,r2,c1,c2;
    char comma;
    int cards[4][4]={{1,3,2,4},{4,2,3,1},{5,7,6,8},{8,6,7,5}};
    
    void main()
    {
    
        char click;
        char newcard;
    
    
    
        cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
        cout<<"@                                                                            @\n";
        cout<<"@                    ##  ## #### ##  ## #### #### # #                      @\n";
        cout<<"@                    # # # # #    # # # # #  # #  # # #                      @\n";
        cout<<"@                    #  #  # ###  #  #  # #  # #### ###                      @\n";
        cout<<"@                    #    # #    #    # #  # # #    #                      @\n";
        cout<<"@                    #    # #### #    # #### #  # ###                      @\n";
        cout<<"@                                                                            @\n";
        cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n";
    
    
        choosePlay(click);
    
      do{
          playGame(r1,c1,r2,c2);
            match(cards);
    
          cout<<"any card does not open?((Y)es or (N)o)";
          cin>>newcard;
    
      }while(newcard =='Y');
    
        //this pushes the next board onto a blank screen
        for (int b=0; b<=5; b++){
            cout<<endl;
        }
    
        cout<<"YOU ARE THE WINNER!!"<<endl;
      getch();
    }
    
    //----------------------------------------------------------------------------//
    
    void choosePlay(char c){
    
    
        cout<<"WELCOME TO MEMORY GAME"<<endl;
        cout<<"DO YOU WANT TO PLAY THIS GAME?\n"<<endl;
        cout<<"(y/n)\n\n";
        cin>>c;
    
        if(c=='y'){
            //display board
            cout<<"\n\n    1  2  3  4\n"<<endl;
            cout<<"  ";
    
            for (int i=0; i<=6; i++)
            {
                cout<<" -";
            }
          cout<<endl;
    
        for (int r=0; r<4; r++)
        {
            cout<<r+1<<" | ";
            for (int c=0; c<4; c++)
            {
                cout<<" * ";
            }
            cout<<endl;
        }
        cout<<endl;
      }
        else if(c=='n') {
                cout<<"Thank you for enter this game"<<endl;
          }
    }
    
    
    //-----------------------------------------------------------------------------//
    
    void playGame(int s1,int d1,int s2,int d2){
    
    
        //selection
        cout<<"Please insert the first card row and column seperated by a comma.\n";
        cin>>s1>>comma>>d1;
        cout<<"Please insert the second card row and column seperated by a comma.\n";
        cin>>s2>>comma>>d2;
        //fix
        s1--;
        d1--;
        s2--;
        d2--;
        cout<<s2<<d2;
    
        //reveal
        cout<<"\n\n    1  2  3  4\n";
        cout<<"  ";
        for (int i=0; i<=6; i++)
        {
            cout<<" -";
        }
        cout<<endl;
    
        for (int r=0; r<4; r++)
        {
            cout<<r+1<<" | ";
            for (int c=0; c<4; c++)
            {
                if ((r==s1)&&(c==d1))
                {
                  cout<<"  ";
                }
                else if((r==s2)&&(c==d2))
                {
                    cout<<"  ";
    
                }
                else
                {
                    cout<<" * ";
                }
            }
            cout<<endl;
        }
    }
    
    //----------------------------------------------------------------------------//
    
    void match(int cards[4][4]){
    
        //match?
    
        if (cards[r1][c1]==cards[r2][c2])
        {
        cout<<"  ";
        }
      else
        {
        }
    }
    i hope someone can help me to change it...
    thanks for your cooperation :)
    Last edited by Dormilich; Nov 13 '10, 08:19 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    just replace all console i/o operators with corresponding printf and scanf.

    Comment

    • Jose Diaz
      New Member
      • Nov 2010
      • 6

      #3
      Hey I rewrote and fix all the problems:
      there is still some problem with the logic in if conditions. If you have any question write me back i will gladly assist you =).

      Code:
      #include <stdio.h>
      #include <conio.h>
       
      void choosePlay(char);
      void playGame(int,int,int,int);
      void match(int[][4]);
      int r1,r2,c1,c2;
      char comma;
      
      
      
      int cards[4][4]={{1,3,2,4},{4,2,3,1},{5,7,6,8},{8,6,7,5}};
       int main()
      {
       
          char click;
          char newcard;
       
       
      
       
          printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
          printf("@                                                                            @\n");
          printf("@                    ##  ## #### ##  ## #### #### # #                      @\n");
          printf("@                    # # # # #    # # # # #  # #  # # #                      @\n");
          printf("@                    #  #  # ###  #  #  # #  # #### ###                      @\n");
          printf("@                    #    # #    #    # #  # # #    #                      @\n");
          printf("@                    #    # #### #    # #### #  # ###                      @\n");
          printf("@                                                                            @\n");
          printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
       
       
          choosePlay(click);
       
        do{
            playGame(r1,c1,r2,c2);
              match(cards);
       
            printf("any card does not open?((Y)es or (N)o)");
            scanf("%c",&newcard);
       
        }while(newcard =='Y');
       
          //this pushes the next board onto a blank screen
          int b=0; //cannot be in for loop cannot be created 
          for (b=0; b<=5; b++){
              printf("\n"); //replace endl with \n for newline
          }
       
          printf("YOU ARE THE WINNER!!\n");
        getch();
      }
       
      //----------------------------------------------------------------------------//
       
      void choosePlay(char c){
       
       
          printf("WELCOME TO MEMORY GAME\n");
          printf("DO YOU WANT TO PLAY THIS GAME?\n\n"); //place 2 newline dint know if that is what you wanted
          printf("(y/n)\n\n");
          scanf("%c",&c);
       
          if(c=='y'){
              //display board
              printf("\n\n    1  2  3  4\n\n");
              printf("  ");
               int i=0;
              for (i=0; i<=6; i++)
              {
                  printf(" -");
              }
            printf("\n");
       int r=0;
          for (r=0; r<4; r++)
          {
              printf("%d \"| '",r+1);
              int c=0;
              for (c=0; c<4; c++)
              {
                  printf(" * ");
              }
              printf("\n");
          }
          printf("\n");
        }
          else if(c=='n') {
                  printf("Thank you for entering this game ");
                
            }
      }
       
       
      //-----------------------------------------------------------------------------//
       
      void playGame(int s1,int d1,int s2,int d2){
       
       
          //selection
          printf("Please insert the first card row and column seperated by a comma.\n");
          scanf("%d",&s1);
          scanf("%d",&d1);
      
          printf("Please insert the second card row and column seperated by a comma.\n");
          
          scanf("%d",&s2);
          scanf("%d",&d2);
        
          //fix
          s1--;
          d1--;
          s2--;
          d2--;
          printf("%d %d",s2,d2);
       
          //reveal
          printf("\n\n    1  2  3  4\n");
          printf("  ");
          int i=0;
          for (i=0; i<=6; i++)
          {
              printf(" -");
          }
          printf("\n");
       int r=0;
          for (r=0; r<4; r++)
          {
              printf("%d | ",r+1);
              int c=0;
              for (c=0; c<4; c++)
              {
                  if ((r==s1)&&(c==d1))
                  {
                    printf("  ");
                  }
                  else if((r==s2)&&(c==d2))
                  {
                      printf("  ");
       
                  }
                  else
                  {
                      printf(" * ");
                  }
              }
              printf("\n");
          }
      }
       
      //----------------------------------------------------------------------------//
       
      void match(int cards[4][4]){
       
          //match?
       
          if (cards[r1][c1]==cards[r2][c2])
          {
          printf("  ");
          }
        else
          {
          }
          
          //label if you want to start again
          //cls will clear screen  and pause 
          //system("pause");
          //system("cls");
          //main(); call again if you want to start or write do-while to start the entire process
         
        
      }

      Comment

      Working...