Help with functions

This is a discussion on Help with functions within the C++ Programming forums, part of the General Programming Boards category; Ok, My assignment is to create 2 functions, then call those functions from a menu. I have the menu part, ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    6

    Unhappy Help with functions

    Ok,

    My assignment is to create 2 functions, then call those functions from a menu. I have the menu part, and I think my functions are numerically correct but I get this error

    warning C4700: uninitialized local variable 'ci' used
    warning C4700: uninitialized local variable 'cc' used

    Here is the program:

    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    void ci2cc(double& cubinch)
    {
    double  cc, ci;
    cc = ci*16.387064;
    
    } // cubic inch to cubic centimenter
    
    void cc2ci(double& cubcent)
    {
    double cc,ci;
    ci = cc/16.387064;
    } // cubic centimeter to cubic inch
    
    
    void main()
    {
    double cubinch, cubcent;
    int select;
    do
    {
    cout << " 0 : Exit the program. \n"<< " 2 : Convert Cubic inch to cc. \n"
    << " 3 : Convert cc to Cubic inch. \n";cout << "Please enter the selection : ";
    cin >> select;
    
    switch(select)
    {
    
    case 0 : cout << "Program teminates. \n";
    break;
    
    case 1 : cout << "Please enter a value in cubic inches : ";
    cin >> cubinch;
    ci2cc(cubinch);
    cout << "" << cubinch << " cubic inch = " << cubcent << " cubic centimeter " << endl;
    break;
    
    case 2 : cout << "Please enter a value in cubic centimeters : ";
    cin >> cubcent;
    cc2ci(cubcent);
    cout << "" << cubcent << " cc = " << cubinch << " Cubic inches " << endl;
    break;
    
    default : cout << "Invalid selection.\n";
    } // switch
    }while(select != 3);
    } // main
    I can't figure out what it means --- when I run the program the menu come up right, but it will not run the funtion. :/


    Thanks in advance!

    Jessica

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Do you not know what the word uninitialized means???

    Code:
    void ci2cc(double& cubinch)
    {
    double  cc, ci;
    cc = ci*16.387064;
    
    } // cubic inch to cubic centimenter
    What is the value of ci in that function, for example?

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Instead of
    Code:
    double cubinch, cubcent;
    do something like
    Code:
    double cubic;
    and have it save to this variable instead of cubinch, and cubcent the put thins
    Code:
    return cubic;
    and in the function put this
    Code:
    double ci /*or cc*/ = main();

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,648
    bijan311, I think that you might want to explain what you are saying more clearly as "and cubcent the put thins" is meaningless to me.

    Note that it is illegal to call the global main function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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, 02: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

Tags for this Thread


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