Hello,
Could somebody tell me how to pass something from one function to another? For example, say I had 3 functions, one to get two numbers, one to add the two numbers together, and one to take that total and add tax to it. I'm trying to understand how to take the total from adding 2 numbers in one function and returning it to another to add tax to the total from the other function. I hope this makes sense. I'll post what I'm trying to do. This works ok until I try to add the tax function. Thanks. mcorn
code:--------------------------------------------------------------------------------
Code:
#include<iostream.h>
void GetCookieQty(float *,float *);
float CalcCookiePrice(float,float);
//float GetTaxes(); //new
#define l_price .95;
#define r_price .50;
//#define tx_rate .05; //new
int main(void)
{
float howmany;
float ptr1,ptr2,tax;
GetCookieQty(&ptr1,&ptr2);
howmany=CalcCookiePrice(ptr1,ptr2);
// tax=GetTaxes(); //new
return 0;
}
void GetCookieQty(float *ptr1,float *ptr2)
{
cout<<"\nHow many large cookies? ";
cin>>*ptr1;
cout<<"How many regular cookies? ";
cin>>*ptr2;
}
float CalcCookiePrice(float ptr1,float ptr2)
{
float num1,num2,num3;
cout.precision(2);
cout.setf(ios::showpoint | ios::fixed);
num1= ptr1 * l_price;
num2= ptr2 * r_price;
num3= num1+num2;
cout<<"\n"<< num1 << " for large cookies."
<<"\n"<< num2 << " for regular cookies."
<<"\n\nThe total is " << num3<<endl<<endl;
return num3; //this was return 0;
}
//float GetTaxes(float num4) //new
//{
// return num4=num3*tx_rate;
//cout<<num3; //new
//}
[code][/code]tagged by Salem