/* ______________________________________________________ CS 121 LESSON 6: FUNCTIONS WITH PARAMETERS AND A RETURN TYPE NATIVE CODE VERSION Ron Kessler Created 1/4/2017 This solution introduces functions that take arguments and have a return type This app calls my DisplayWelcome function then prompts the user for two numbers to add up. I then call CalculateTotal as pass that funtion the numbers to add up. This way we do not use any globals which is the best way to do it. Run with CTL-F5 */ #include "stdafx.h" #include using namespace std; void DisplayWelcome (); //define the function frameworks here //this time the function is designed with 2 parameters AND a return type double CalculateTotal (double currentBalance, double deposit); int main () { //---first show the welcome banner DisplayWelcome (); //call my custom function //---prompt for numbers to add up double currBalance; double newDeposit; cout.precision (2); cout << "Please enter your current bank balance...."; cin >> currBalance; cin.ignore (); cout << "\n\nPlease enter your deposit amount...."; cin >> newDeposit; cin.ignore (); double grandTotal = CalculateTotal (currBalance, newDeposit); //ask the funtion to add our numbers cout << "\n\nYour new balance is now $" << fixed << grandTotal << "\n\n\n\n"; return 0; } //my helper functions. Make sure it is not inside main() void DisplayWelcome () { cout << ( "_____________________________________________\n" ); cout << ( "Welcome to Ron's Stop & Rob ATM Service.\n" ); cout << ( "_____________________________________________\n\n\n" ); return; //all done so return to the code that called this guy } double CalculateTotal (double startingBalance, double deposit) //the function accepts 2 arguments(the data you send it) { //---notice here the math is done locally and then the result is returned to the calling code. return startingBalance + deposit; //do the math with the data passed in and return the answer }