// Native_FunctionsWithReturn.cpp : Defines the entry point for the console application. /* ______________________________________________________ CS 121 LESSON 6: FUNCTIONS WITH A RETURN TYPE NATIVE CODE VERSION Ron Kessler Created 1/4/2017 This solution introduces functions Functions are blocks of code that do a job for us. They are called functions when the are NOT inside of a class. When they are inside a class we call them Methods. They do/act the same. This app calls my DisplayWelcome function then prompts the user for two numbers to add up. This function is marked int which means it is returning an integer value to the code that called it. Run with CTL-F5 */ #include "stdafx.h" #include using namespace std; void DisplayWelcome (); //define the function frameworks here int AddThem (); int firstNum = 0; //create some variables int secondNum = 0; int main () { //---first show the welcome banner DisplayWelcome (); //call my custom function //---prompt for numbers to add up cout << "Please enter first number to add : "; cin >> firstNum; cin.ignore (); cout << "Please enter second number to add : "; cin >> secondNum; cin.ignore (); int myAnswer = AddThem (); //jump/call myAnswer to do the math and return the result cout << "\n\nYour sum turns out to be : " << myAnswer << "\n"; return 0; } //my helper functions. Make sure it is not inside main() void DisplayWelcome () { cout << ( "_____________________________________________\n" ); cout << ( "Welcome to your friendly Calculator.\n" ); cout << ( "_____________________________________________\n\n\n" ); return; //all done so return to the code that called this guy } int AddThem () //here int defines the type of data that is returned { return firstNum + secondNum; //this adds the numbers and returns the result }