I've tried but I don't understand how to use void, can someone please try to explain how it works in a simple way.
#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
float areacalc( float rad);
float circumcalc( float rad);
void output(float A, float C);
void input ( void );
float radius; // Deklaration av en global variabel
int main( )
{
input( );
float circum, area;
area= areacalc( radius);
circum = circumcalc( radius);
output( area, circum);
return 0;
}
float areacalc( float rad)
{
float circlearea;
circlearea = rad*rad*3.14;
return circlearea;
}
float circumcalc ( float rad)
{
return 2*rad*3.14;
}
void output(float A, float C)
{
cout.setf(ios::fixed);
cout<<setprecision(2);
cout<<"area = "<< A<<" centimetre^2"<<endl;
cout<<"Circumference = "<< C<<" Centimetre"<<endl;
}
void input ( void )
{
cout<<"Input the circle radius: ";
cin>> radius;
}
This is an example in my book but I don't understand where you get the value for "A", "C" or "rad" when it's not given a value anywhere in the code. I feel really stupid, that I don't get it.
Also can someone please show me what this program should look like:
Write a program that uses a function with following prototype: float add(float a, float b); to calculate the sum of two numbers.
Should look something like this:
Input two numbers: 10 30
Sum = 40