40 C:\Documents and Settings\Admin\Desktop\me cpu\Untitled4.cpp [Warning] the address of `double memberCost(int, int, int)', will always evaluate as `true'
anyone know why? im trying to pass information from case 2 to case 3 to compute cost
void menu();
void info();
void charges();
void userInfo (int monthsPaid, int sessionAmt, int age);
double memberCost (int monthsPaid, int sessionAmt, int age);
int main ()
{
int response, monthsPaid, sessionAmt, age;
do
{
menu ();
cin >> response;
cout << endl;
switch (response)
{
case 1:
cout << "Here is some basic gym information, as well as prices and discounts" << endl << endl;
info ();
charges ();
break;
case 2:
cout << "Please enter the following information with spaces in between." << endl << "Months of membership, Sessions, and Age." << endl << endl;
userInfo(monthsPaid, sessionAmt, age);
break;
case 3:
memberCost (monthsPaid, sessionAmt, age);
cout << "This program is menu-driven, either by pressing"
<< " 1, 2, 3 or 4. " << endl << endl;
cout << "1: You will be able to obtain pertinent"
<<" information about the gym and its \n prices." << endl << endl;
cout << "2: You will be asked to enter your "
<< "personal information and services required." << endl << endl;
cout << "3: You will be able to view your membership "
<< "cost from your \n information provided." << endl << endl;
cout << "4: To terminate the program." << endl;
}
void info ()
{
cout<< "The gym is open 7 days a week from 8am - 8pm" << endl << endl;
}
void charges ()
{
cout << "Prices \n" << endl << "1 month of membership = $10 \n" << "1 session = $10 " << endl << endl;
cout << "Discounts \n" << endl << "Purchase of 12 or more months = 15% per month \nPurchase of more than 5 sessions = 20% per session \n"
<< "Senior citizen discount (60 and older) = 30% off membership cost" << endl << endl;
}
void userInfo (int monthsPaid, int sessionAmt, int age)
{
void info (string gymInfo)
{
string gymInfo = cout << "The gym is open 7 days a week from 8am - 8pm";
}
in main,
info (gymInfo);
should just be info();
You had gymInfo as an undeclared variable being used as a parameter. It was confusing you since you had the function of the same name. The function is fine.
Make sure to change the prototype to reflect the change.
That depends on the purpose of the function.
For example, say you want a function to merely display data, like the one you have.
1 2 3 4 5
void myFunction (int myVariable)
{
//just displaying it
cout << myVariable << " is my variable.";
}
On the other hand, you can use functions to modify data that you have in your main function.
1 2 3 4 5
void myFunction (int & myVariable)
{
//changing variable in main
++myVariable;
}
This function increments the variable sent from the main function.
You will want to include the '&' in the function if you intend to change a value in the main function. Or else you can just return a value as well, an assign that to a variable in your main function.
void menu();
void info();
void charges();
void userInfo (int& monthsPaid, int& sessionAmt, int& age);
double memberCost ();
int main ()
{
int response;
do
{
menu ();
cin >> response;
cout << endl;
switch (response)
{
case 1:
cout << "Here is some basic gym information, as well as prices and discounts" << endl << endl;
info ();
charges ();
break;
case 2:
cout << "Please enter the following information with spaces in between." << endl << "Age, Months of membership, and Sessions required." << endl << endl;
userInfo(int& monthsPaid, int& sessionAmt, int& age);
break;
case 3:
double memberCost (int monthsPaid, int sessionAmt, int age);
break;
case 4:
cout << "program terminate" << endl;
break;
default:
cout << "Invalid input" << endl;
break;
return 0;
}
}
while (response != 4);
return 0;
}
void menu ()
{
cout << "This program is menu-driven, either by pressing"
<< " 1, 2, 3 or 4. " << endl;
cout << "1: You will be able to obtain pertinent"
<<" information about the gym and its \n prices." << endl;
cout << "2: You will be asked to enter your "
<< "personal information and services required." << endl;
cout << "3: You will be able to view your membership "
<< "cost from your \n information provided." << endl;
cout << "4: To terminate the program." << endl;
}
void info ()
{
cout<< "The gym is open 7 days a week from 8am - 8pm" << endl << endl;
}
void charges ()
{
cout << "Prices \n1 month of membership = $10 \n" << "1 session = $10" << endl << endl;
cout << "Discounts \n Purchase of 12 or more months = 15% \n Purchase of more than 5 sessions = 20% \n Senior citizen discount (60 and older) = 30%"
<< endl << endl;
}
When you call the function (first line) you're not using the value it returns
I'm not sure how the compiler interprets memberCost, but the second time you're not calling the function. To do that it should be cout<< "Your membership cost is =$" << memberCost(monthsPaid, sessionAmt, age) << endl << endl;