I've made a program that was supposed to just return a value for the function selected while using x and y which are global variables. All that it outputs is the location of the data in the memory and not the actual value. I was thinking maybe I could just leave it and place a reverse pointer in there somewhere but I'm not sure how to do that... Any tips?
cout << "Please enter a value for x" << endl;
cin >> x ;
cout << "Please enter a value for y" << endl;
cin >> y ;
do
{
cout << "which function would you like to compute? 1, 2, or 3? press 0 to exit." << endl;
cin >> choice;
while ((choice < 0) || (choice > 3))
{
cout << " you have entered an invalid choice... please try again." << endl ;
cout << "which function would you like to compute? 1, 2, or 3? press 0 to exit." << endl;
cin >> choice;
}
if (choice == 1)
{
cout << " the value of function one is " << function1 << endl;
}
if (choice == 2 )
{
cout << " the value of function 2 is " << function2 << endl;
}
if (choice == 3 )
{
cout << " the value of function 3 is " << function3 << endl;
}
}while ((choice >= 1)&&(choice <=3));
cout << " goodbye"<< endl;
return 0;
}
float function1(void)
{
float F= 0.0;
F = 2 * (x * x * x * x) + 9 * (1/(y * y));
return F;
}
float function2(void)
{
float F = 6 * x + 5 * (y*y*y);
return F;
}
float function3(void)
{
float F = ( x * x * x ) + (1/( y * y * y ));
return F;
}
I've made a program that was supposed to just return a value for the function selected while using x and y which are global variables.
First, please use code tags when posting code. The code you posted is practically unreadable.
Second, this is illegal
Code:
float main(void)
The main() function returns int and only int.
Code:
int main()
Third, to call a function, you must provide arguments within parentheses. If there are no arguments, then you just specify parentheses only. You did not do that at all (look at your cout statememts).
Regards,
Paul McKenzie
Last edited by Paul McKenzie; November 6th, 2009 at 11:14 AM.
Bookmarks