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;
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";
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.