Trouble connecting main.cpp, BoxClass.h, BoxClass.cpp

I created a basic consol program that creates a box of the users desired height and width. I wanted to learn how classes worked so I just used one file. Now i'm trying to properly put the class into a .h and .cpp file. I have a whole bunch of errors concerning the variables. Can someone point out what I'm doing wrong and how I should fix it? BTW all my cpp and header files are in the same folder.

Sorry for some reason I can't use bold, italics, etc.


ConsolApplication1.cpp(aka main.cpp):

#include "BoxClass.h"
#include "stdafx.h"
#include <iostream>
using namespace std;


int main() {
//variable declaration/definition
int width_Var;
int height_Var;
int number_of_Boxes;

//object declaration/Body
cout << "Enter width of rectangle/box\nWidth = ";
cin >> width_Var;
cout << "Enter height of rectangle/box\nHeight = ";
cin >> height_Var;
cout << "How many rectangles/boxes do you want?\n";
cin >> number_of_Boxes;

BoxClass box1(width_Var, height_Var, number_of_Boxes);

cout <<"Box Area = "<<box1.Rectangle_Area() << endl;

//exit
cout << "\n\n\n\n\n";
system("pause");
return 0;
}



BoxClass.h:

#ifndef BOXCLASS_H
#define BOXCLASS_H

class BoxClass {
//prv variables
unsigned short int width;
int height, i;
float space_Value;
float height_Count;
bool error;
//prv functions
void Print_Rectangle(int x, int y);

public:
//function shows area of individual spaces
float Rectangle_Area();
//function shows area of individual spaces

// constructor
BoxClass(int x, int y, int amount);
};

#endif



BoxClass.cpp:

#include "BoxClass.h"
#include "stdafx.h"
#include <iostream>
using namespace std;


void BoxClass::Print_Rectangle(int x, int y) {

//calc
space_Value = (3 * x) - 4;

//draw top of box
for (width = 1; width < x; width += 1) {
cout << "...";
}
cout << "\n";

//draw sides
for (height = 1; height < y; height += 1) {
cout << ":";
height_Count++;
for (width = 1; width < space_Value; width += 1) {
cout << " ";
}

cout << ":\n";
}

//draw bottom
cout << ":";

for (width = 1; width < space_Value; width += 1) {
cout << ".";
}
cout << ":\n";
}


//function shows area of individual spaces
float BoxClass::Rectangle_Area() {
if (error == false) {
return (height_Count - .5)*(space_Value - 1);
}
else {
return 0;
}
}

// constructor
BoxClass::BoxClass(int x, int y, int amount) {
float height_Count = 1;
bool error = false;

if (x <= 41) {
for (i = 1; i <= amount; i += 1) {
Print_Rectangle(x, y);
}
}
else {
error = true;
cout << "Error - width must be below 42!\n";
}
};



ERRORS:

1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>BoxClass.cpp
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(7): error C2653: 'BoxClass': is not a class or namespace name
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(10): error C2065: 'space_Value': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(13): error C2065: 'width': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(19): error C2065: 'height': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(21): error C2065: 'height_Count': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(22): error C2065: 'width': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(22): error C2065: 'space_Value': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(32): error C2065: 'width': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(32): error C2065: 'space_Value': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(40): error C2653: 'BoxClass': is not a class or namespace name
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(41): error C2065: 'error': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(42): error C2065: 'height_Count': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(42): error C2065: 'space_Value': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(50): error C2653: 'BoxClass': is not a class or namespace name
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(50): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(55): error C2065: 'i': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\boxclass.cpp(63): warning C4508: 'BoxClass': function should return a value; 'void' return type assumed
1>ConsoleApplication1.cpp
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(21): error C2065: 'BoxClass': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(21): error C2146: syntax error: missing ';' before identifier 'box1'
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(21): error C3861: 'box1': identifier not found
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(23): error C2065: 'box1': undeclared identifier
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(23): error C2228: left of '.Rectangle_Area' must have class/struct/union
1>c:\users\cade\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(23): note: type is 'unknown-type'
1>Generating Code...
1>Done building project "ConsoleApplication1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
@laquishabonquiquithe3rd

Not sure if this will fix everything, but #include "stdafx.h" has to be the first line in the list of includes. I don't believe you need it though, in the class files. I may be wrong, as I write all my programs in just one source code.
1
2
#include "BoxClass.h"
#include "stdafx.h" 
stdafx.h is vs thing to speed up compilation
it seems to be ignoring the includes before it, iirc, it should be the first thing in your sources
1
2
#include "stdafx.h"
#include "BoxClass.h" 


> Sorry for some reason I can't use bold, italics, etc.
[code]
 
  Put the code you need help with here.
[/code]
@ne555 @whitenite1 Thank you both so much that fixed everything.
Topic archived. No new replies allowed.