void main problem

i am trying to use this given tutorial and main needs to be void for future tutorials, but every time i compile it as void, it gives an error saying main must return an int. Although on the tutorial it worked.
I know math.h and string do not need to be there, but it is for future purposes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <math.h>
#include <string>
using namespace std;


void main()
{
    int people;
    float bill, tip, totaltip, total;

    cout << "How much is the bill? ";
    cin >> bill;
    cout <<"How many people will be splitting the bill? ";
    cin >> people;
    cout << "What is the percetage of the tip? ";
    cin >> tip;

    totaltip = bill *(tip/100.);
    total = (totaltip + bill) /people;

    cout << "The total tip at %" << tip << " is $" << totaltip << '.' << endl;
    cout << "Each person will pay $" << total << '.' << endl;
   
}
Last edited on
metulburr wrote:
main must return an int
Last edited on
though it works on other peoples tutorials?
I would probably find a different tutorial...

The standard says main must return an int, but apparently some compilers will let you get away with void. I just tested with msvc 2010, and it will compile

1
2
3
void main()
{
}


without warning.
yeah dude, main() most definitely returns an int. Consider this simple boilerplate code:
int main(int nArgs, char* pszArgs)

its kinda just what i was told to impliment in all my main methods and i would be safe
Topic archived. No new replies allowed.