• Log in or sign up for an account here: https://www.sythe.org/login

need help fixing this program

renzcy24

Newcomer
Joined
Sep 30, 2011
Sythe Gold
0
Messages
1
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;
   }
}
 
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.
 
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.

Well those two would cause the program not to complie. Fixing those should fix his issues.
 
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;
}

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

Those would've probably just caused warnings.
 
Code:
Those would've probably just caused warnings.[/quote]

It would definitely cause an error.

Also, you're right about the function declarations.  Been a while since I've done any C++.

You can either declare your functions above main or declare them underneath main and include prototypes for the functions above main.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
or use a header file.

That's the same thing as prototyping; the contents of the header are substituted for the 'include' line during compilation...
 
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.

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.
 
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.

I prefer to be consistent and put it in anyway.
 
That's the same thing as prototyping; the contents of the header are substituted for the 'include' line during compilation...

True, I was just mentioning it as it tends to keep your code more organized and help with readability.
 
Runescape Gamblingrunescape gambling
Back
Top