Original Post
Hi ppl. I was mucking around with functions and I realised that you can't access an integer/floating point/etc outside of its function :( I know this isn't big news, to you or myself, but is there any workaround to solve my problem? This is my function: I was trying something like this(assuming my function is in a header file): Of course, that doesn't work and even if it did, it would be useless. Just an example. Can my problem be solved while keeping my function? Or will I have to use some sort of class instead? [Edited by - chrisparton1991 on December 4, 2009 7:18:58 PM]
void getTriangleArea(float base, float height, bool output)
{
float area = (0.5 * base) * height;//formula
if(output == true)//if you want it outputted
{
cout << area << endl;//outputs triangle area
}
else//or not
{}
}
#include <iostream>
#include <stdio.h>
#include "myHeader.h"
using namespace std;
int main()
{
getTriangleArea(30, 10, false)
cout << area << endl;
system("pause");
return 0;
}