-
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
-
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?
-
Instead of
Code:
double cubinch, cubcent;
do something like
and have it save to this variable instead of cubinch, and cubcent the put thins
and in the function put this
Code:
double ci /*or cc*/ = main();
-
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.