-
November 6th, 2009, 11:44 AM
#1
Help on a program that returns a pointer?
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?
#include <iostream>
using namespace std;
float x = 0.0;
float y = 0.0;
float function1(void);
float function2(void);
float function3(void);
float main(void)
{
int choice = 0;
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;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|