Thread: Convert c++ program to c

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    1

    Post Convert c++ program to c

    I have just started learning c,i had already learned c++.So,i m rookie in c programming.I have written a program in c++,i want it to be converted to c program.So,plz do me a favour.

    Plz convert the following c++ source code to c source code:
    Code:
    #include <iostream.h>
    #include<conio.h>
    #include <time.h>
    #include<string.h>
    void main ()
    
    {int Day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    char nameday[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    int mo,dy,yr,c=0,j;
    cout<<"Enter Years:";
    cin>>yr;
    if(yr<1928) ;
    yr-=1928;
    j=(yr)/4;
    yr%=7;
    cout<<"Enter month:";
    cin>>mo;
    if(mo<1 || mo>12) ;
    cout<<"Enter day:";
    cin>>dy;
    if(dy<1 || dy>31) ;
    for(int i=0;i<mo-1;i++)
    {
    c+=Day[i];
    }
    dy+=yr;
    c+=dy;
    c+=j;
    c%=7;
    cout<<nameday[c]<<endl;
    getch();
    }

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Replace #include<iostream.h> with #include <stdio.h> as well.
    And it's int main(), not void main().

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    and learn to indent your code... ow my eye.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Not to mention this is not C++... this is C-- (my word for non-standard C++!).
    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.

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Not that it has anything to do with the "conversion", but there are some erroneous semicolons floating about your program.
    Code:
    if(yr<1928) ;  <--???
    yr-=1928;
    j=(yr)/4;
    yr%=7;
    cout<<"Enter month:";
    cin>>mo;
    if(mo<1 || mo>12) ;  <--???
    cout<<"Enter day:";
    cin>>dy;
    if(dy<1 || dy>31) ;  <--???
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    I think you need to re-acquaint yourself with the space bar and tab button.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  8. #8
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Quote Originally Posted by Elysia View Post
    Not to mention this is not C++... this is C-- (my word for non-standard C++!).
    Lol, I like that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. Convert a C++ program?
    By unregistered in forum C Programming
    Replies: 4
    Last Post: 05-22-2002, 02:44 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM