+ 1

Calling function

I wanna call the function calculate to do the math then i wanna take the variables from the function calculate to put it in. The function print bill and print it ...help ! —————— calculate function float calculate ( char pc , int bw ) { float amount ; switch (pc) { case 'F': { if(bw<=30) { amount=0.0; } else if (bw>30) { amount=bw-30; amount=amount*10; if (bw>=50) amount=amount*0.05; } break; } case 'B': { if(bw<=25) { amount=0.0; } else if (bw>25) { amount=bw-25; amount=amount*10; } break; } case 'E': { if(bw<=20) { amount=0.0; } else if (bw>20) { amount=bw-20; amount=amount*10; } break; } } return amount ; } /////PrintBill function void printbill(string mm , char pc , float amount ) { cout<<"*********AIRLINE******\n"; cout<<"MemberShip Number:"<<mm<<"\n"; if (pc=='f'||pc=='F') { cout<<"Class"<<"First/n"; } if (pc=='e'||pc=='E') { cout<<"Class"<<"Economy/n"; } if (pc=='b'||pc=='B') { cout<<"Class"<<"bussniess/n"; } cout<<"Total Charge"<<fixed<<setprecision(2)<<amount<<"SR\n"; cout<<"*****************************"; }

19th Nov 2019, 12:55 AM
wojod
1 Odpowiedź
+ 1
The function calculate can only give one return value. This variable you can get in the main function of your programm by passsing it to a variable like: void main(){ float am = calculate ( pc , bw ); printbill(mm, pc, am) } If you want more variables to pass to your second function you could use CallByReference in your first function and give your results finally in the function calculate to the referenced variables: Example: CallByReference: float calculate ( char & pc , int &bw ){ .... calculation ... pc = resultOfCalculation; bw = result2OfCalculation; } You only have to take care your not changing the variable references during calculation. Hopefully could help you. Greetings Axel
20th Nov 2019, 10:12 AM
Axel Gottwald
Axel Gottwald - avatar