void Home::display()
{
cout << "Square footage of your home is: " << squareFootage << "ft^2." << "\n";
cout << "Max floor space is : " << maxFloorSpace << "ft^2." << "\n";
cout << "The amount of square ft which you can expand your home is: " << areaOfExpansion << "ft^2" << "\n";
}
};
int main()
{
double w,d,f;
Home h;
cout << "Please enter the width of your land: ";
cin >> w;
while (w < 1) {
cout << "Please enter a positive number \n";
cin >> w;
}
h.setWidth(w);
cout << "Please enter the depth of your land: ";
cin >> d;
while (d < 1) {
cout << "Please enter a positive number \n";
cin >> d;
}
h.setDepth(d);
cout << "Please enter the floor space of your property: ";
cin >> f;
while (f < 1) {
cout << "Please enter a positive number \n";
cin >> f;
}
h.setFloorSpace(f);
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
When I loaded your program into the IDE I first noticed that you are missing a semi-colon at the end of some lines.
The first step is to compile your program before posting it here and if there are any error messages you do not understand include them in your message.
When I fix the errors I will have a better idea of what is happening. I will know something shortly.
Awesome thanks, I will edit it and try to run it soon I wrote it on text edit because xcode won't let me run anything😑. Im going to school to work more on it over there I will post again after I try to get it running over there. Thanks again!
#include<iostream>
#include<math.h>
usingnamespace std;
#include<string>
int main()
{
double w,d,f;
Home.h;
cout << "Please enter the width of your land: ";
cin >> w;
while (w < 1) {
cout << "Please enter a positive number \n";
cin >> w;
}
h.setWidth(w);
cout << "Please enter the depth of your land: ";
cin >> d;
while (d < 1) {
cout << "Please enter a positive number \n";
cin >> d;
}
h.setDepth(d);
cout << "Please enter the floor space of your property: ";
cin >> f;
while (f < 1) {
cout << "Please enter a positive number \n";
cin >> f;
}
h.setFloorSpace(f);
h.calSquareFootage();
h.calMaxFloorSpace();
h.calAreaOfExpansion();
h.display();
return 0;
}
ok I think I have fixed the issues in the above code that you have mentioned, I am now trying to run it and the main error codes I'm getting are
Error 2 error C2228: left of '.h' must have class/struct/union c:\users\skylib\documents\visual studio 2012\projects\project1\project1\source.cpp 11 1 Project1
Without checking the new code what I first see is:
Lines 13 and 14 in the class code the semi-colon at the end of the line is not needed. Only the semi-colon inside the closing } is needed.
Line 10 in main should be Home h;. The dot is what is causing the error. A space is defining an object. The ".h" is trying to access in the class that does not exist and the ".h" would only work on an object of the class which you do not have yet. A good example is what you do at line 17.
In main line 39 you call the function h.calAreaOfExpansion();. In the function definition you use the variable "f", but it is never defined anywhere. I found that "f" needs to be passed to this function.
line 2 in main you should use "<cmath>" in place of "<math.h>".
Also you should learn not to use the line usingnamespace std; Someday in the future this WILL cause you a problem.
line 9 in main you should ALWAYS initialize your variables. double w{},d{},f{};. The empty {}s will initialize these variables to 0.0. Otherwise these variables would contain an unknown value. If used before they receive a usable number the results are unpredictable.
I will load up this version and see if there is anything else.
#include "Home.hpp"
#include <iostream>
#include <cmath>
usingnamespace std;
Home::Home()
{width = 0; depth = 0; floorSpace = 0;};
Home::Home(double w, double d, double f)
{ width=w; depth=d; floorSpace=f; }
void Home::calSquareFootage()
{ squareFootage = width * depth; }
void Home::calMaxFloorSpace()
{ maxFloorSpace = (width * depth) * .7;};
void Home::calAreaOfExpansion()
{ areaOfExpansion = ((width * depth)* .7) - floorSpace;
while ( areaOfExpansion < 1){
cout << "Im sorry but you can not expand your floor space as your property already reaches the maximum floor space for County" << endl;
cin.get();
}
};
void Home::display()
{
cout << "Square footage of your home is: " << squareFootage << "ft^2." << "\n";
cout << "Max floor space is : " << maxFloorSpace << "ft^2." << "\n";
cout << "The amount of square ft which you can expand your home is: " << areaOfExpansion << "ft^2" << "\n";
};
First i just wanna say thanks again Andy you've been a huge help. Everything is running now but when the while loop is met in calAreaOfExpansion function it printss the message twice.