Need help with an error please

This is a discussion on Need help with an error please within the C++ Programming forums, part of the General Programming Boards category; Hey all, ive just started to learn C++ and this is my first post. Im making a simple program just ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    3

    Question Need help with an error please

    Hey all, ive just started to learn C++ and this is my first post. Im making a simple program just to put together all that ive learned so far, but im getting the error:

    Error C2447: '{' : Missing function header (old style formal list?)

    Below is my code, thanks for any help in advance

    Code:
    #include <iostream>
    
    using namespace std;
    
    // This is my very first project, It has no real use, i dont even know what it is
    // its just a simple program for me to mess around with what ive learned so far.
    // By Michael Clarke 8/6/2007
    
    	int money = 100;
    	int total = 0;
    	int buy = 0;
    
    int main();
    {
    
    
    	// Money is used for how much money i have in pence.
    	// Total is something i will use later to help with the numbers.
        // buy will be used for input from the user.
    
    	cout << "You have: " << money << endl;
    	cout << "Would you like to buy a coke for 75p?" << endl;
    	cout << "please press '1' for yes and '0' for no: ";
    	cin >> buy;
    	
    	if buy == 1;
    	{
    		cout << "Thank you, That will be 75 Pence please" << endl;
    		money - 75;
    	}
    
    	if buy == 0;
    	{
    		cout << "Ok, Come again!" << endl;
    	}
    
    	else;
    	{
    		cout << "Please input a 0 for no or a 1 for yes" << endl;
    	}
    
    	cout << "thank you, have a nice day!" << endl;
    	cout << "You have: " << money << "in Change" << endl;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > int main();
    This has a trailing ; which you don't need.

    > if buy == 0;
    Missing ( ), and spare ;
    Try
    if ( buy == 0 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    3
    Thanks salem, your answer worked. i also had to change 'money - 75' to 'money = (money - 75)

    After that is was fine thanks again =)

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    You might consider using money -= 75 which is the short form of money = money - 75. The result is the same but I prefer -=.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21