I have a sample code project that I would like to offer the community for their use. Full source provided. (Teaching what I've learned helps me learn).
#include "stdafx.h"
#include <iostream>
usingnamespace std;
//our custom function with two parameters (float x and float y);
float myFunc(float x, float y){
//multiplies the parameters;
float answer = x*y;
//returns and stores the answer for later use in our main function;
return answer;
}
//the main function;
int main ()
{
//declare floats;
float a, b;
//user prompt;
cout << "Enter two numbers to multiply \n";
//user input;
cin >> a;
cin >> b;
//print the returned value;
cout << myFunc(a, b) << "\n";
//pause the computer system;
cin.get();
}
Just to elaborate what vlad is saying, your function returns a value, so simply calling it was pointless as the value was returned, then lost. Using cout, you print that value.
Yes, I don't like the system pause method, but I needed the console open long enough for me to see it. Usually, in a longer program, I will just return the entire script to the main function.
I have a search algorithm I completed last month, do you guys want to review the source? The user enters a search item, and it displays the result as well as the index location of its array.