Thread: havn't completed the code yet but is it okay cause i doubt my loop parts????????

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    Lightbulb havn't completed the code yet but is it okay cause i doubt my loop parts????????

    Code:
    #include<iostream.h>
    Code:
    #include<conio.h>
    #include<fstream.h>
    #include<string.h>
    
    
    
    
    class company
    {
        char comp_name[30];
        float sales_figr,indstry_sales_figr,entrprise_valu,net_wrkin_capitl;
        float EBIT,net_fixd_asst;
    public:
        float markt_share,earnin_yeild,return_on_capitl;
        void input ()
        {
            cout<<"Company name:";
            gets(comp_name);
            cout<<"\nCompany sales figure:";
            cin>>sales_figr;
            cout<<"\nIndustry sales figure:";
            cin>>indstry_sales_figr;
            cout<<"\nEnterprise value:";
            cin>>entrprise_valu;
            cout<<"\nEBIT:";
            cin>>EBIT;
            cout<<"\nNet fixed asset:";
            cin>>net_fixd_asst;
            cout<<"\nNet working capital:";
            cin>>net_wrkin_capitl;
        }
        void calc()
        {
             markt_share=(sales_figr/industry_sales_figr);
             earnin_yeild=(EBIT/(net_fixd_asst+net_wrkin_capitl) ;
        }
        void output () 
        {
             cout<<"\nCompany name  :   ";
             puts(comp_name);
             cout<<"\nMarket Share  :   ";
             cout<<markt_share;
             cout<<"\nEarning Yield :   ";
             cout<<earnin_yeild;   
        }    
    };
    int main()
    {    company c[5];
        ofstream fo("COMPANY.txt",ios::out);
                    for(i=0,i<5,i++)
                    {
                        c[i].input();
                        while(!fo.eof())
                        {
                            fo.write((char*) &c[i],sizeof(c[i]));
                        }
                    }
                    fo.close();
    
    
    
        ifstream fi("COMPANY.txt",ios::in);
                    for(i=0,i<5,i++)
                    {
                        c[i].output();
                        while(!fi.eof())
                        {
                            fi.write((char*) &c[i],sizeof(c[i]));
                        }
                    }
                    fi.close();
    
    
    
    
    
    
    }
    
    

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > for(i=0,i<5,i++)
    Use ; not , to separate the control elements of a for loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Never ever use gets. It's such a serious security risk that it's being removed from the language. Use std::getline along with std::string to read a string instead. E.g.:

    std::string s;
    std::getline(std::cin, s);
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures, code completed. Creating the comments
    By alvarito in forum C Programming
    Replies: 8
    Last Post: 10-05-2011, 05:10 AM
  2. Explain this c language code....only 2 parts of it?
    By ankit8946 in forum C Programming
    Replies: 22
    Last Post: 10-31-2009, 03:33 PM
  3. C source code to split any given file into many parts
    By m.sudhakar in forum C Programming
    Replies: 2
    Last Post: 08-15-2006, 03:43 AM
  4. Completely seperating parts of code
    By Boksha in forum C++ Programming
    Replies: 3
    Last Post: 08-14-2005, 11:36 AM
  5. I'm not green, I havn't even germinated
    By Ican'tCjax,fl in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-27-2002, 06:18 PM