In: Computer Science
Write a C++ program using separate void which asks the user to input side of a square, radius of a circle , height and base of a triangle and finds the area of squares, circles and triangles. Then using main function display the area of square, circle and triangle
#include<iostream>
using namespace std;
//reads the input into variables using references
void readInput(double &side,double &radius,double &height ,double &base){
cout<<"Enter side of sqaure: ";
cin>>side;
cout<<"Enter radius of circle: ";
cin>>radius;
cout<<"Enter base and height of triangle: ";
cin>>base>>height;
}
int main(){
double side,radius,height,base;
readInput(side,radius,height,base);
// formula : a^2
cout<<"Square area: "<<side * side<<endl;
// formula 2 PI R
cout<<"Circle area: "<<2 * 3.1415 * radius<<endl;
// formula BH/2
cout<<"Triangle area: "<<base * height/2<<endl;
}