need help fixing this program

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

need help fixing this program
  1. Unread #1 - Sep 30, 2011 at 9:55 AM
  2. renzcy24
    Joined:
    Sep 30, 2011
    Posts:
    1
    Referrals:
    0
    Sythe Gold:
    0

    renzcy24 Newcomer

    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;
       }
    }
     
  3. Unread #2 - Sep 30, 2011 at 9:50 PM
  4. The Fat Controller
    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1

    The Fat Controller Guru

    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.
     
  5. Unread #3 - Oct 1, 2011 at 3:19 AM
  6. blindkilla
    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord

    blindkilla Guru
    $25 USD Donor New

    need help fixing this program

    Well those two would cause the program not to complie. Fixing those should fix his issues.
     
  7. Unread #4 - Oct 1, 2011 at 12:32 PM
  8. The Fat Controller
    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1

    The Fat Controller Guru

    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.
     
  9. Unread #5 - Oct 1, 2011 at 1:13 PM
  10. blindkilla
    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord

    blindkilla Guru
    $25 USD Donor New

    need help fixing this program

     
  11. Unread #6 - Oct 1, 2011 at 6:11 PM
  12. wackywamba
    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1

    wackywamba Guru

    need help fixing this program

    or use a header file.
     
  13. Unread #7 - Oct 1, 2011 at 9:49 PM
  14. Govind
    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

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    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...
     
  15. Unread #8 - Oct 7, 2011 at 2:23 PM
  16. BotsInc
    Joined:
    Aug 12, 2011
    Posts:
    78
    Referrals:
    0
    Sythe Gold:
    0

    BotsInc Member

    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.
     
  17. Unread #9 - Oct 7, 2011 at 11:09 PM
  18. The Fat Controller
    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1

    The Fat Controller Guru

    need help fixing this program

    I prefer to be consistent and put it in anyway.
     
  19. Unread #10 - Oct 8, 2011 at 4:31 AM
  20. wackywamba
    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1

    wackywamba Guru

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site