Question: I keep getting an error regarding double inclusion in my code. I have the include guard for my header file, but it just won't work.
I keep getting an error regarding double inclusion in my code. I have the include guard for my header file, but it just won't work. I cannot figure out what is wrong with my code. It consists of 3 separate files. (in C++)
figures.h:
#ifndef FIGURES #define FIGURES void filledsquare(int n); void hollowsquare(int n); void slash(int n); void backslash(int n); void diamond(int n); int n; int operation; int z = 1; char filled; #endif
figures.cpp:
#include
using namespace std;
void filledsquare(int n) { // print square for (int i = 0; i < n; i++) { // nested loop for (int j = 0; j < n; j++) { // print asterisk cout << "*"; } // break cout << endl; } } void hollowsquare(int n) { // prints hollow square for (int i = 0; i < n; i++) { // nested loop for (int j = 0; j < n; j++) { // check if (i == 0 || j == 0 || i == n - 1 || j == n - 1) { // print asterisk cout << "*"; } else { // print space cout << " "; } } // break cout << endl; } } void slash(int n) { // print diagonal for (int i = 0; i < n; i++) { // nested loop for (int j = 0; j < n; j++) { // check if (i == j) { // print asterisk cout << "*"; } else { // print space cout << " "; } } // break cout << endl; } } void backslash(int n) { // prints second diagonal for (int i = 0; i < n; i++) { // nested loop for (int j = 0; j < n; j++) { // check if (i + j == (n - 1)) { // print asterisk cout << "*"; } else { // print space cout << " "; } } // break cout << endl; } } void diamond(int n) { // prints diamond for (int i = 0; i <= n; i++) { // nested loop for (int j = n; j > i; j--) { // print space cout << " "; }
// print asterisk cout << "*";
// check if (i > 0) { // nested loop for (int k = 1; k <= z; k++) { // print space cout << " "; } z += 2; // print asterisk cout << "*"; } // break cout << endl; }
z -= 4;
for (int i = 0; i <= n - 1; i++) { // nested loop for (int j = 0; j <= i; j++) { // prints space cout << " "; }
// prints asterisk cout << "*";
// nested loop for (int k = 1; k <= z; k++) { // prints space cout << " "; }
z -= 2;
// check if (i != n - 1) { // prints asterisk cout << "*"; }
//break cout << endl; } }
figureInput.cpp:
#include
using std::cin; using std::cout; using std::endl;
int main() { cout << "Input number:"; cin >> n;
cout << "SELECT A FIGURE"; cout << endl; cout << " 1. square"; cout << endl; cout << " 2. slash"; cout << endl; cout << " 3. backlash"; cout << endl; cout << " 4. diamond"; cout << endl;
cin >> operation;
switch (operation) {
//case 1 - square case 1: cout << "Input size:"; cin >> n; cout << "Filled or hollow? F for filled, H for hollow"; cin >> filled; if (filled == 'f' || filled == 'F') { void filledsquare(int n); } else { void hollowsquare(int n); }
break;
//case 2 - slash case 2: cout << "Input size:"; cin >> n; void slash(int n); break;
//case 3 - backslash case 3: cout << "Input size:"; cin >> n; void backslash(int n); break;
//case 4 - diamond case 4: cout << "Input size:"; cin >> n; void diamond(int n); break; } while (operation >= 1 && operation <= 4); //ensures the user input is valid
//denides invalid input cout << "INPUT INVALID, TRY AGAIN"; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
