Adblock breaks this site

need help fixing this program

Discussion in 'Programming General' started by renzcy24, Sep 30, 2011.

  1. renzcy24

    renzcy24 Newcomer

    Joined:
    Sep 30, 2011
    Posts:
    1
    Referrals:
    0
    Sythe Gold:
    0
    need help fixing this program

    Code:
    #include <iostream>
    #include <iomanip>
    #include <conio>
    
    double main(void)
    {
       void Heading();
       double Table();
       getch();
    }
    void Heading()
    {
    	cout<<"--------------------------------------"<<endl;
       cout<<setw(12)<<"Product Cost Table"<<setw(12)<<endl;
       cout<<"--------------------------------------"<<endl;
       cout<<"Number Produce"<<setw(6)<<"Cost"<<endl;
       cout<<"--------------------------------------"<<endl;
       cout<<"--------------------------------------"<<endl;
    }
    double Table()
    {
    	double produced[5]={300,400,500,600,700};
       double cost[5];
       for(int k=0;k<5;k++)
    	{
       	cost[k]=produced[k]*3.46;
       	cout<<produced[k]<<setw(6)<<cost[k]<<endl;
       }
    }
     
  2. The Fat Controller

    The Fat Controller Guru

    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1
    need help fixing this program

    main() should have return type int and return 0 at the end.
    Table() should have a void, not double, return type.

    Those shouldn't break the program though.
     
  3. blindkilla

    blindkilla Guru
    $25 USD Donor New

    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord
    need help fixing this program

    Well those two would cause the program not to complie. Fixing those should fix his issues.
     
  4. The Fat Controller

    The Fat Controller Guru

    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1
    need help fixing this program

    Ah, I saw the actual problem. Table() and Heading() aren't declared when they are called, and they aren't being called correctly anyway. main() should come after the other functions, and look like this:

    Code:
    
    //other function definitions here
    
    int main(void)
    {
       Heading();
       Table();
       getch();
    
       return 0;
    }
    
    Those would've probably just caused warnings.
     
  5. blindkilla

    blindkilla Guru
    $25 USD Donor New

    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord
    need help fixing this program

     
  6. wackywamba

    wackywamba Guru

    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1
    need help fixing this program

    or use a header file.
     
  7. Govind

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus
    need help fixing this program

    That's the same thing as prototyping; the contents of the header are substituted for the 'include' line during compilation...
     
  8. BotsInc

    BotsInc Member

    Joined:
    Aug 12, 2011
    Posts:
    78
    Referrals:
    0
    Sythe Gold:
    0
    need help fixing this program

    Since the main function is a special function that returns 0 by default it is not necessary to return anything according to the ISO standard. In C++ tutorials main() returns a value to introduce the general function return-value-concept.
     
  9. The Fat Controller

    The Fat Controller Guru

    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1
    need help fixing this program

    I prefer to be consistent and put it in anyway.
     
  10. wackywamba

    wackywamba Guru

    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1
    need help fixing this program

    True, I was just mentioning it as it tends to keep your code more organized and help with readability.
     
< Cheat Macro Community Project | Checkers >


 
 
Adblock breaks this site