my basic function wont work

I really dont understand why it wont work its copyed out of a book please help it says there is an error with the hello().
//
//
//
#include<iostream>
#include<math.h>
using namespace std;
int main (void)
{
int a,b,s;
hello ();
cin>>a>>b;
s=a+b;
cout<<s;
bye()
}
void hello(void){
cout<<"hello how are you today?"<<endl;
}
void bye (void){
cout<<"goodbye have a nice day<<endl;
}
system("PAUSE");
}


Please use [code][/code] tags around the code.

There is a missing semicolon after the call to bye(). The system("PAUSE") stuff seems like it was tacked on by someone who didn't understand what "add it to the end of your program" meant, so if that's from your book I suggest you find another one.
1. Looks like a mixture of C and C++.
2. Please use code tags to present code in this forum. See http://cplusplus.com/articles/z13hAqkS/ .
3. You are missing a semicolon in the last line of main().
4. You are missing a double quote inside the bye() function.
5. Please ALWAYS post the compiler errors that you get as they are useful in determining what is going on.
6. Any decent IDE should provide coloring of code. Colors make code look prettier but most importantly they help in finding syntax errors. For example, a good IDE that colors string literals should have colored <<endl as a string literal inside bye(), being a clear indication that the closing quote is missing.

If you require further help don't hesitate to ask.
Last edited on
Multiple problems

1) The functions hello and bye should be moved above main, after "using namespace std;"
Functions should be defined (or forward declared) before their use.

2) In cout<<"goodbye have a nice day<<endl; the ending double quote is missing

3) There is an extra } between cout and system("PAUSE");

4) There is semicolon missing after bye()

Generally use "code" style to post code it makes reading easier, be careful not to type extra "}" and remember to type ";"

Also, avoid using system("PAUSE"); see http://www.cplusplus.com/forum/beginner/1988/
instead of using system("PAUSE"); you can use return 0; but you want these at the very end of main instead of the end of your program. There is various ways to terminate.
@Endl3ss: I think the purpose was to hold the command prompt/console not to exit the program

Compiler should have already given error (or at least warning) for not returning from a function having return type. main has return type of int, need to return an int
main is "special" with regard to needing to return a value. Letting it fall off the end without a return statement is equivalent to returning 0. A compiler shouldn't complain about it.
Topic archived. No new replies allowed.