void areatriangle (int base, int height, int &result)
{
result=(base*height)/2;
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Area of Triangle: ";
//Declare variables for base height and answer
int base1, int base2, int answer;
base1=2;
base2=3;
areatriangle(base1, base2, answer);
cout<<"\nThe Area of triangle is: " <<answer;
_getch;
return 0;
}
The neat thing about compiler errors are they say what is wrong. Could you copy/paste it? Also they are functions not void functions. Void is the return type telling the compiler there is nothing being returned. Which also means you should remove the return on line 4 it is doing absolutely nothing.
*on a side note you are also trying to do integer division on line 3.
Please post the full error (Line, CharAt, e.What).
EDIT:
Okay I see... You need to change the ampersand on line 1 to a * because you need a pointer. Then you need to switch result= on line 2 to *result= (because your pointer is really a normal int). Also, you need to dereference answer on line 17 to call it in as an int pointer. Fixed code shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void areatriangle (int base, int height, int *result) {
*result=(base*height)/2;
}
int _tmain(int argc, _TCHAR* argv[]) {
cout<<"Area of Triangle: ";
//Declare variables for base height and answer
int base1, int base2, int answer;
base1=2;
base2=3;
areatriangle(base1, base2, &answer);
cout<<"\nThe Area of triangle is: " <<answer;
_getch;
return 0;
}
>c:\users\pc\desktop\c++ programming\void function area\void function area\void function area.cpp(21): error C2062: type 'int' unexpected
1>c:\users\pc\desktop\c++ programming\void function area\void function area\void function area.cpp(24): error C2065: 'base2' : undeclared identifier
1>c:\users\pc\desktop\c++ programming\void function area\void function area\void function area.cpp(26): error C2065: 'base2' : undeclared identifier
1>c:\users\pc\desktop\c++ programming\void function area\void function area\void function area.cpp(26): error C2065: 'answer' : undeclared identifier
1>c:\users\pc\desktop\c++ programming\void function area\void function area\void function area.cpp(28): error C2065: 'answer' : undeclared identifier
1>c:\users\pc\desktop\c++ programming\void function area\void function area\void function area.cpp(29): warning C4551: function call missing argument list
Wait, we haven't covered pointers yet in class though. Is there not another way usandfriends to fix this issue? Also, when I click on debut, I get a message from this popupbrowser saying "the system cannot find the file specified
Oh lol I wasn't pay attention I thought you had semi colons on line 9 but you have commas. When you do a list like that using the comma operator you only put the type for the left most variable.
so it should be
int base1 , base2 , answer;
Other than that and the extra return statement that you should remove the code looks good.
On a side note you can initialize when you declare a variable: