im a newbie to c++ and im trying to calling a function of a class in another one but the output just doesnt come out right. I tried to calculate the total cost repeatedly according to different areas, but the output always garbled. i think i have declared it? This is my code:
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<iomanip>
#include<numeric>
#include<conio.h>
using namespace std;
class RoomDimension
{
public:
double width;
double length;
double area;
double getarea(void);
void room(int,int);
};
double RoomDimension::getarea()
{
return area;
}
class RoomCarpet: public RoomDimension
{
public:
double costpermeter;
double totalcost=0;
double gettotalcost(void);
void calculation();
};
double RoomCarpet ::gettotalcost()
{
return totalcost;
}
void RoomDimension::room(int n, int m)
{
RoomCarpet rc;
cout<<"Number of rooms= ";
cin>>m;
if(m<1)
{
cout<<"Invalid input."<<endl;
}
for (n = 0;n < m;++n)
{
cout<<"Length of the room= ";
cin>>length;
if(length==0)
{
cout<<"Invalid input.";
return;
}
cout<<"Width of the room= ";
cin>>width;
if(width==0)
{
cout<<"Invalid input.";
return;
}
area=width*length;
cout<<"Area of the room= "<<area<<endl;
rc.calculation();
}
return;
}
void RoomCarpet::calculation()
{
RoomDimension rd;
totalcost=0;
cout<<"Price per square meter= ";
cin>>costpermeter;
if(costpermeter==0)
{
cout<<"Invalid input."<<endl;
return;
}
double totalcost=costpermeter*rd.area;
cout<<"Total price= RM"<<totalcost<<endl;
return;
}
int main()
{
RoomDimension rd;
rd.room(0,0);
return 0;
}
and the output keep showing like this
Number of rooms= 2
Length of the room= 5
Width of the room= 4
Area of the room= 20
Price per square meter= 5
Total price= RM5.03097e-317
Length of the room= 3
Width of the room= 7
Area of the room= 21
Price per square meter= 7
Total price= RM7.04336e-317
what should i do to fix that?