help in transfoming C++ code into regular ansi C..

This is a discussion on help in transfoming C++ code into regular ansi C.. within the C Programming forums, part of the General Programming Boards category; Because this c++ code is a complete solution to my problem . Unfortunately i cant see the logic of it. ...

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Because this c++ code is a complete solution to my problem .
    Unfortunately i cant see the logic of it.
    and there are too many commands which are needed to be replaced.

    and i now very little c++.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    And now you have erased everything C++, and all that's left is C. Yet you still struggle.
    I'm just saying - I don't think this is a good idea!
    If you have an assignment, why should you hunt for solutions when you should write the code yourself?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,312
    Quote Originally Posted by transgalactic2
    Because this c++ code is a complete solution to my problem .
    Unfortunately i cant see the logic of it.
    So, you happened to find this C++ program somewhere, and basically want to copy it, but you have to hand in a C program compilable under C90.

    Clearly, your assignment is not about transforming a C++ program into a C program, which was what I thought you were trying to do. I believe others who contributed to this thread thought the same. Rather, the aim was for you to develop a solution to the problem and implement it in C.

    What you should be asking for is help in understanding the solution that you have found so that you can re-implement it in C. Mechanically translating the solution from C++ to C is tantamount to plagarism, and arguably as bad as finding a solution in C and handing it up as your own work. You may even be guilty of copyright infringement if you do not have permission to copy and make a derivative work.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    It was written in c++ specifically for my problem.
    I did not steal it.
    I have built some thing close.

    But it gives me the right a right pair numbers many times .
    for input 54 it gives me 12 42 12 42 12 42 (it should give me only one pair) 12 42
    and it doesnt give me the result for 53 52 .. 1
    (whether they are a sum of two abounded numbers)

    i tried to trace with a debugger but i cant see the problem
    ??
    Code:
    
    
    #include <stdio.h>
    
    
     //////////////////////////////////////////////////////////////00000000
    
    int  main(){
        int num;
        int index,tndex,kndex,jndex;
        int flag_1,flag_2,same_num;
        int sum;
        int smallest,smallest_ever,smallest_ever_2;
        sum=0;
        same_num=-1;
    
        smallest=-1;
    
        printf("enter number\n");
        scanf("&#37;d",&num);
    
        for(index=1;index<num;index++){ //start for main number
            flag_1=0;
    
            sum=0;
        flag_2=0;
    
             tndex=index;
                 kndex=num-tndex;
    
    
                           sum=0;
                        for(jndex=1;jndex<tndex;jndex++){//start abbondence check for first num (tndex)
                            if (tndex%jndex==0){
                                sum=sum+jndex;
                            }
                            if (tndex<sum){
                            flag_1=1;
                        }
    
                        }//end abbondence check for first num
    
    
                        sum=0;
                        for(jndex=1;jndex<kndex;jndex++){//start abbondence check for second num (kndex)
                            if (kndex%jndex==0){
                                sum=sum+jndex;
                            }
                         if (kndex<sum){
                            flag_2=1;
                        }
    
                        }//end abbondence check for first num
    
                        if ((flag_2==1)&&(flag_1==1)){  //start flag check
                            if (kndex>=tndex){
                                smallest=tndex;
    
                                if ((smallest<smallest_ever)&&(smallest>1)){
                                    smallest_ever=smallest;
                                    smallest_ever_2=kndex;
                                }
                            }
                            else
                            {
                                smallest=kndex;
                                if ((smallest<smallest_ever)&&(smallest>1)){
                                    smallest_ever=smallest;
                                    smallest_ever_2=tndex;
                                }
                            }
    
                             printf("%d %d\n",smallest_ever,smallest_ever_2);
                            }
    
                        }//end flag check
    
    
    
    
    
    
    
    
    
      return 0;
    }//end main
    Last edited by transgalactic2; 12-08-2008 at 04:53 AM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 08:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21