Thread: Help with functions

  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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 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

Tags for this Thread