>Nothing was returned
Standard C++ returns 0 by default. Returning from main can be tricky, especially if you switch languages and work with legacy code a lot. In pre-standard C++ you need to explicitly return a value. In C89 you need to explicitly return a value. In standard C++ and C99, you can omit the return value and 0 will be returned automagically.
However, because C99 isn't widely implemented yet, everyone follows the intersection of C89 and C99 to avoid nonportable code during the interrim of changing from old standard to new standard. Since standard C++ is well implemented now, it's safe to omit the return value, but many still do it explicitly anyway as a matter of style and consistency.
My preference is to omit the return value unless I return failure, then I return success explicitly as well:
// Don't return anything explicitly
using namespace std;
if ( some_failure )
return EXIT_FAILURE; // Return failure here
return EXIT_SUCCESS; // And success here
>don't you have to put something inside the braces?
No, an empty block is legal. It's roughly equivalent to:
if ( something )
But that uses a semicolon, so it's not a valid solution for the problem. ;)
Oh, and read the intro threads on how to post code, specifically
tags before posting more code.
you study well in C ok after that you go to other. in C we don't need to specify int infront of main(),because it was a default in C. void means empty. that is the main doesn't return anything........ok?
> void means empty. that is the main doesn't return anything........ok?
No, main returns an int - didn't you read anything I posted?
You don't have a choice in this, you don't get to decide that main returns void without breaking your program. Sure, your current sloppy compiler may allow you to say "works for me", but that just isn't good enough round these parts. Upgrade your compiler, and all of a sudden, all your old code (and old ideas) are broken.
> in C we don't need to specify int infront of main(),because it was a default in C
True, but not saying anything is NOT the same as saying void.
Besides, you should be aware that all the implicit declarations in C are deprecated - meaning that it is only supported for old code, and any new code should really be written in "say what you mean".
>in C we don't need to specify int infront of main(),because it was a default in C.
Not anymore. The latest standard removed implicit int from the language. All of your code will now fail to compile. Sorry.
>void means empty.
void means nothing.
>that is the main doesn't return anything........ok?
No, not OK. main is required by the language specification to return int. If you don't return int, your code is broken. It's just that simple. You don't have a choice. This is the correct definition of main that works under all C standards:
int main ( void )
Your void main isn't required to work under any of them.
Good job, Rammohan from Banalore! Your m4d sk1llz as a Technical lead in a big IT firm have helped you answer a trivial question over a year after the rest of us with code that would have worked beautifully fifteen years ago but would fail to compile on at least one very widely used modern compiler. :icon_rolleyes:
public class GrossmontBank
//class variables (global - accessible throughout this class)
//scanner object to be used throughout
private static Scanner input = new Scanner(System.in);