"&" is an address of. Use this sign for declaration and definition.
#include <iostream>
using namespace std;
void triangle(int, int, int&, int&);
int main(){
int base = 6;
int height = 4;
int area;
int circumference;
triangle(base, height, area, circumference);
cout << "Triangle arithmatics" << endl;
cout << "base: " << base << " & height: " << height << endl;
cout << "Area: " << area << endl;
cout << "Circumference: " << circumference << endl;
return 0;
}
void triangle(int base, int height, int& area,
int& circumference){
area = 0.5 * base * height;
circumference = base + (2 * height);
}
No comments:
Post a Comment