Variables and Functions

This is a discussion on Variables and Functions within the C++ Programming forums, part of the General Programming Boards category; I'm pretty new to c++, I've only been doing it a short time, so I'm not entirely sure whats wrong ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Variables and Functions

    I'm pretty new to c++, I've only been doing it a short time, so I'm not entirely sure whats wrong with this program.

    I've looked over notes I have about functions and variables, and it all seems correct. I'm not sure what exactly the problem is, but I hope someone can help ^^

    I'm trying to make a 'game' purely out of cout, cin and only basic functions.

    Code:
    /*
      Name: Text Based RPG Game
      Author: Tony Jordan
      Date: 29/03/06 14:06
      Description: A text based game made comprising purely of basic C++ features, such as cin, cout and filestreams.
      Some minor math (addition, subtraction, random numbers) are present.
    */
    
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <conio.h>
    #include <math.h>
    
    using namespace std;
    
    //FUNCTIONS
    //NEW GAME
    void NewGame(void)
    {
         cout << "New Game Starting!";
         getch();
    }    
    
    //LOAD GAME
    void LoadGame(void)
    {
         cout << "Loading";
         getch();
    }
         
    //QUIT GAME
    void Exit(void)    
    {
    
         char quit;
         
         cout << "Are you sure you want to quit?" << endl;
         cin >> quit;
         if ((quit=='Y') || (quit=='y')) 
         {
          cout << "Quitting" << endl;
         }
    }
    
    //ABOUT
    void About(void)
    {
      cout << "Name: Text Based RPG Game" << endl;
      cout << "Author: Tony Jordan" << endl;
      cout << "Date: 29/03/06 14:06" << endl;
      cout << "Contact Email: webmaster@darknovax.com" << endl;
    }
    
    int Menu(void)
    {
        int option;
        
        cout << "*******************************************************************" << endl;
        cout << "*******************************************************************" << endl;
        cout << "************************* [GAME NAME HERE] ************************" << endl;
        cout << "*******************************************************************" << endl;
        cout << "*******************************************************************" << endl;
        cout << endl;
        cout << endl;
        cout << "                              --Menu--" << endl;
        cout << "            Please enter a menu choice to begin." << endl;
        cout << "1. Start a New Game" << endl;
        cout << "2. Load an Existing Game" << endl;
        cout << "3. About" << endl;
        cout << "4. Exit the Game" << endl;
        cin >> option;
        
        while ((option < 1) || (option > 4))
        {
              cout << endl;
              cout << "Not a valid option. Try again" << endl;
              cin >> option;
    }
    
        return option;
    }
    
            //Constants
            
            //Variables
            //Player Variables
            
            /*
            HP is Players Current HP
            MaxHP is Players Maximum HP
            MP is Players Current MP
            MaxMP is Players Maximum MP
            Str is players strength/attack power
            Def is players defensive ability
            Mag is players Majik
            MagDef is players Majik Defence
            Level is players Level (1, 2, 3, etc)
            EXP is the amount of experience player has
            EXPTNL is amount of experience player needs to level up, when EXP == EXPTNL, player gains 1 level.
            Job is players Job name
            Name[16] is players name, maximum 15 characters long
            */
        
        int HP, MaxHP, MP, MaxMP, Str, Def, Mag, MagDef, Level, EXP, EXPTNL;
        char Name[16], Job; 
        
        //General Variables
        /*
        Choice is the menu choice
        
        */
        
        int choice;
        
    
    //MAIN    
        
    int main(void)
    {
        do
        {
              choice=Menu();
        
              if (choice == 1)
              {
                 NewGame();
              }
              else if (choice==2)
              {
                 LoadGame();
              }
              else if (choice==3)
              {
                 About();
              }              
          } while (choice != 4);
    
        }
        
        return 0;
    }
    I get these errors when I try to compile it:

    C:\Documents and Settings\Tony\My Documents\bored\main.cpp:140: error: expected unqualified-id before "return"

    C:\Documents and Settings\Tony\My Documents\bored\main.cpp:140: error: expected `,' or `;' before "return"
    C:\Documents and Settings\Tony\My Documents\bored\main.cpp:141: error: expected declaration before '}' token



    If it help's at all, I'm using Bloodshed Dev C++ 4.9.9.2 on Windows XP.


    Many Thanks in Advance

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Try this
    Code:
    int main(void)
    {
        do
        {
              choice=Menu();
        
              if (choice == 1)
              {
                 NewGame();
              }
              else if (choice==2)
              {
                 LoadGame();
              }
              else if (choice==3)
              {
                 About();
              }              
          } while (choice != 4);
    	return 0;
    }
    Look at last brace!
    Also, you should use cmath and not math.h
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Oh, now i notice what I did wrong ><

    Thanks a lot for the help! It works fine now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parse a program for functions, variables
    By Enu in forum C Programming
    Replies: 2
    Last Post: 02-15-2006, 11:08 AM
  2. Question about Static variables and functions.
    By RealityFusion in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2005, 03:31 PM
  3. Static variables and functions problem in a class
    By earth_angel in forum C++ Programming
    Replies: 16
    Last Post: 09-15-2005, 01:08 PM
  4. Variables do not equal functions!!!
    By me@burk. in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 06:24 AM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 02:39 PM

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