Thread: Recalling Functions?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    18

    Recalling Functions?

    First off, I'd just like to point out that I'm quite new to C++. Anyways, I'm trying to make an inline function return to the main function if a switch case is met. The compiler error is as follows:

    --------------------Configuration: healthfair - Win32 Debug--------------------
    Compiling...
    healthfair.cpp
    C:\CS151\healthfair\healthfair.cpp(66) : error C2065: 'main' : undeclared identifier
    C:\CS151\healthfair\healthfair.cpp(97) : error C2373: 'main' : redefinition; different type modifiers
    Error executing cl.exe.

    healthfair.exe - 2 error(s), 0 warning(s)

    Here is the code (I will bold and enlarge the two error lines for easier reading):

    Code:
    // Health Fair
    // Created by Ty Guenley
    // 02-09-05
    
    #include <iostream.h>
    
    // Required header and namespace for colors
    #include "Console.h"
    namespace con = JadedHoboConsole;
    
    // Body Mass Index Inline Function
    inline void bmi()
    {
        // Required Variables
        char bmireturn;
        int feet, inches, pounds;
        float meters, kilograms, bmi;
    
        // Required stream for colors
        using std::cout;
        using std::endl;
    
        // Clear Screen
        cout << con::clr;
    
        // Body Mass Title and Intro
        cout << con::fg_gray << "-" << con::fg_white << "="
            << con::fg_cyan << "Body Mass Index" << con::fg_white
            << "=" << con::fg_gray << "-";
    
        // Get User's Height and Weight
        cout << con::fg_white << "\n\nEnter your " << con::fg_cyan
            << con::bg_blue << "WEIGHT" << con::fg_white << con::bg_black
            << "in pounds: ";
        cin >> pounds;
        cout << con::fg_white << "\n\nEnter your " << con::fg_cyan
            << con::bg_blue << "HEIGHT" << con::fg_white << con::bg_black
            << "... ";
        cout << "\n\tFeet: ";
        cin >> feet;
        cout << "\tInches: ";
        cin >> inches;
    
        // Make Calculatations
        inches = (feet * 12) + inches;
        meters = inches * (float)0.0254;
        kilograms = pounds / (float)2.2;
        bmi = kilograms / (meters * meters);
    
        // Display Results
        cout << "\nYou are " << con::fg_cyan << meters << "m"
            << con::fg_white << " tall.";
        cout << "\nYour mass is " << con::fg_cyan << kilograms << "kg"
            << con::fg_white << ".";
        cout << "\nYour Body Mass Index is " << con::fg_cyan << bmi
            << con::fg_white << ".";
    
        // Return to main()?
    bmim:
        cout << "\n\nWould you like to return to the main menu? "
            << con::fg_gray << "y/n\n";
        cin >> bmireturn;
        switch (bmireturn)
        {
        case 'y':
         main();
            break;
        case 'n':
            cout << con::fg_white << "\nGood-bye!";
            break;
        default:
            cout << con::clr;
            cout << con::fg_white << "\nPlease choose y/n!";
            goto bmim;
            break;
        }
    }
    
    // Weight Loss Inline Function
    inline void weight()
    {
        // Weight Loss Variables
        int sedentary, calories;
    
        using std::cout;
        using std::endl;
        // Clear Screen
        cout << con::clr;
    
        // Weight Loss Title
        cout << con::fg_gray << "-" << con::fg_white << "="
            << con::fg_cyan << "Weight Loss" << con::fg_white
            << "=" << con::fg_gray << "-\n\n";
    }
    
    void main()
    {
        // Required variables
        int select;
    
        using std::cout;
        using std::endl;
    
        // Main Title and Copyleft
        cout << con::clr;
        cout << con::fg_gray << "-" << con::fg_white << "="
            << con::fg_cyan << "Health Fair 2005" << con::fg_white
            << "=" << con::fg_gray << "-\t(L)2005 Ty Guenley";
    
        // Menu Selection
        cout << con::fg_white << "\n\n\t::" << con::fg_gray
            << "Menu" << con::fg_white << "::";
        cout << con::fg_cyan << "\n\n1. " << con::fg_white << "Body Mass Index";
        cout << con::fg_cyan << "\n2. " << con::fg_white << "Weight Loss";
        cout << "\n\nPlease make a selection: ";
        cin >> select;
    
        // Menu Selection Functions
        switch (select)
        {
        case 1:
            bmi();
            break;
        case 2:
            weight();
            break;
        default:
            cout << con::fg_yellow << con::bg_gray << "/" << con::fg_gray
                << con::bg_yellow << "/" << con::fg_yellow << con::bg_gray
                << "/" << con::fg_white << con::bg_red
                << "Error: Please enter a valid choice!" << con::fg_yellow
                << con::bg_gray << "/" << con::fg_gray << con::bg_yellow
                << "/" << con::fg_yellow << con::bg_gray << "/\n"
                << con::fg_white << con::bg_black;
        }
    }
    is there a better way to do this? or is it even possible to do it period?

    the weight() function is not completed as of yet, but i was going to add the same switch to it as well.

    also, in case it matters, i'm using Visual C++ 6.0

    thanks much!
    Last edited by suzumebachi; 02-14-2005 at 12:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM